Forum: Ruby Re: Random gauss numbers? ( and other distributions of rando

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
67bb4df2775f6a6b603347dce7119571?d=identicon&s=25 Nuralanur (Guest)
on 2005-11-30 10:33
(Received via mailing list)
Dear Daniel,

the GNU Scientific Library (GSL) includes pseudo random number
generation
methods.
There is a Ruby binding for this library (Ruby-GSL).

Best regards,

Axel
31ab75f7ddda241830659630746cdd3a?d=identicon&s=25 halostatue (Guest)
on 2005-11-30 13:51
(Received via mailing list)
On 11/30/05, Nuralanur@aol.com <Nuralanur@aol.com> wrote:
> the GNU Scientific Library (GSL) includes pseudo random number  generation
> methods.
> There is a Ruby binding for this library (Ruby-GSL).

Just remember that the GSL is under the GNU GPL, which makes it
inappropriate for some applications.

-austin
280b41a88665fd8c699e83a9a25ef949?d=identicon&s=25 steve (Guest)
on 2005-11-30 17:02
(Received via mailing list)
On Nov 30, 2005, at 1:28 AM, Nuralanur@aol.com wrote:

> the GNU Scientific Library (GSL) includes pseudo random number
> generation
> methods.
> There is a Ruby binding for this library (Ruby-GSL).

Try this, if you don't need high performance...

def rand_normal_float(mean = 0.0, variance = 1.0)
   # sum 12 random numbers uniformly distributed in [0,1]
   sum = 0.0
   12.times { sum += Kernel.rand }
   # adjust for mean and variance
   (variance.to_f * (sum - 6.0)) + mean.to_f
end

--Steve
3cb4fdcf13aad6a7dcae83876b0e784e?d=identicon&s=25 jupp (Guest)
on 2005-12-05 23:12
(Received via mailing list)
Hi!

At Thu, 1 Dec 2005 01:01:39 +0900, Stephen Waits wrote:
> Try this, if you don't need high performance...
>
> def rand_normal_float(mean = 0.0, variance = 1.0)
>    # sum 12 random numbers uniformly distributed in [0,1]
>    sum = 0.0
>    12.times { sum += Kernel.rand }
>    # adjust for mean and variance
>    (variance.to_f * (sum - 6.0)) + mean.to_f
> end

My mathematical intuition says that the Gaussian distribution is
achieved as the limit of the above replacing 12 by N (and 6 by N/2)
and then computing the limit for N versus infinity. Without knowing
the quality of the approximation of using 12 in place of infinity the
approximation is of no practical value. Besides that summing up
pseudo-random numbers may decrease their randomness.

Josef 'Jupp' Schugt
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2005-12-06 15:34
(Received via mailing list)
Take a look at this website.  Shouldn't be hard at all to implement in
ruby.
http://www.taygeta.com/random/gaussian.html

_Kevin
This topic is locked and can not be replied to.