Wanted: RNG with bell-curve distro
Author Message
Wanted: RNG with bell-curve distro

I'm looking for a random number generator which generates random numbers with a
bell curve distribution. For example, if I gave the RNG a range of 0-100, the
most numbers generated near 50. If I gave a range of -4 to +4, then most
numbers would be generated near 0.

Pascal preferred, but other languages ok.
Thanks.

--
Freezone Freeware and Free delphi Components
http://www.*-*-*.com/ http://www.*-*-*.com/
http://www.*-*-*.com/

Fri, 23 Dec 2005 21:40:25 GMT
Wanted: RNG with bell-curve distro
Hi Chuck!

Quote:

> I'm looking for a random number generator which generates random
> numbers with a bell curve distribution. For example, if I gave the
> RNG a range of 0-100, the most numbers generated near 50. If I gave a
> range of -4 to +4, then most numbers would be generated near 0.

just a quick idea:

function myrandom(max: integer) : integer;
begin
myrandom := trunc((random + random) * (max+1) / 2.0 )
{ not 2 * random :-)) }
end;

for range 0..100 use myrandom(100);
to achieve a range of -4 to 4 for example use 'r := myrandom(8) - 4;'

i'm really not sure, if this function will result in the distribution
you're looking for.

kind regards
jochen

Sat, 24 Dec 2005 02:24:52 GMT
Wanted: RNG with bell-curve distro

Quote:
> I'm looking for a random number generator which generates random numbers
with a
> bell curve distribution. For example, if I gave the RNG a range of 0-100,
the
> most numbers generated near 50. If I gave a range of -4 to +4, then most
> numbers would be generated near 0.

a bunch of SWAG-files from (for example) ftp://garbo.uwasa.fi/pc/turbopas
and search for 'gauss'.

Hope that will help

Sat, 24 Dec 2005 03:31:09 GMT
Wanted: RNG with bell-curve distro

Jul 2003 13:40:25 :-

Quote:
>I'm looking for a random number generator which generates random numbers with a
>bell curve distribution. For example, if I gave the RNG a range of 0-100, the
>most numbers generated near 50. If I gave a range of -4 to +4, then most
>numbers would be generated near 0.

<URL:http://www.merlyn.demon.co.uk/pas-rand.htm#RandDist>

--

<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt>   RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.

Sat, 24 Dec 2005 03:43:05 GMT
Wanted: RNG with bell-curve distro
On Mon, 7 Jul 2003 20:43:05 +0100, Dr John Stockton

Quote:

>Jul 2003 13:40:25 :-
>>I'm looking for a random number generator which generates random numbers with a
>>bell curve distribution. For example, if I gave the RNG a range of 0-100, the
>>most numbers generated near 50. If I gave a range of -4 to +4, then most
>>numbers would be generated near 0.

> <URL:http://www.merlyn.demon.co.uk/pas-rand.htm#RandDist>

Just for fun (and to learn something), I read John Stockton's web
page, above, and saw my version of Gauss discussed.  Of course,
there's also the simple-minded approximation from the "Mean tends to a
Gaussian" -- simply add up 12 uniformly-distributed random numbers,
which will be approximately a Gaussian with a mean of 6 and a standard
deviation of [here I forget the details, but it is fairly simple to
derive].  I learned this one years ago from the IBM Scientific
Subroutine Package, written in fortran II (not IV!).

Bob Schor
Pascal Enthusiast

Sat, 24 Dec 2005 10:56:50 GMT
Wanted: RNG with bell-curve distro

Quote:

> I'm looking for a random number generator which generates random numbers with a
> bell curve distribution. For example, if I gave the RNG a range of 0-100, the
> most numbers generated near 50. If I gave a range of -4 to +4, then most
> numbers would be generated near 0.

> Pascal preferred, but other languages ok.
> Thanks.

function ZufallNormal (Mittel, SigmaSqr : double) : double;

begin
ZufallNormal := sqrt(-2 * ln(random)) * sin(2 * pi * random) *
SigmaSqr + Mittel;
end;

Mon, 26 Dec 2005 21:11:10 GMT
Wanted: RNG with bell-curve distro

Quote:
>I'm looking for a random number generator which generates random numbers with a
>bell curve distribution.

tFloat is whatever floating point type you want.  Give it the mean and
standard deviation you want.  rNormal returns the result.  rNormal2
returns two of them in less time than 2 calls to rNormal.

function rNormal( const mean, sd : tFloat) : tFloat;

{ Returns a FP number that is normal with the given mean   }
{ and standard deviation.  Based on the method of G. E. P. }
{ Box, M. E. Muller, and G. Marsaglia in D. E. Knuth, The  }
{ Art of Computer Programming, Volume 2, 3rd ed., pg. 122  }
{ By Jud McCranie, Dec 2, 1986. Slightly revised 5/30/99, 7/14/00  }

{ if execution time is a consideration, it can be modified
to return two variables with each call.  See rNormal2 }

var u1, u2, v1, v2, s : tFloat;

begin { --- rNormal --- }

repeat
u1 := random;
u2 := random;
v1 := 2.0 * u1 - 1.0;
v2 := 2.0 * u2 - 1.0;
s  := sqr( v1) + sqr( v2);
until s < 1.0;

rNormal := mean + sd * sqrt( (-2.0 * ln( s) / s)) * v2;

end; { --- r normal --- }

procedure rNormal2( const mean, sd : tFloat;
out   x1, x2   : tFloat);

{ Returns reals X1 and X2 that are normally distributed with      }
{ the given mean and standard deviation.  Based on the method     }
{ of G. E. P. Box, M. E. Muller, and G. Marsaglia in D. E. Knuth, }
{ The Art of Computer Programming, Volume 2, 3rd ed., pg. 122     }
{ By Jud McCranie, Dec 2, 1986. Slightly revised 5/31/99, 7/14/00 }

var u1, u2, v1, v2, s, thing : tFloat;

begin { --- rNormal2 --- }

repeat
u1 := random;
u2 := random;
v1 := 2.0 * u1 - 1.0;
v2 := 2.0 * u2 - 1.0;
s  := sqr( v1) + sqr( v2);
until s < 1.0;

thing := sqrt( (-2.0 * ln( s)) / s);
x1    := mean + sd * v1 * thing;
x2    := mean + sd * v2 * thing;

end; { --- r normal2 --- }

Mon, 26 Dec 2005 23:01:59 GMT

 Page 1 of 1 [ 7 post ]

Relevant Pages