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

**URL:** <https://www.ruby-forum.com/t/re-random-gauss-numbers-and-other-distributions-of-rando/49124>\
**Category:** Ruby\
**Created:** [November 30, 2005, 10:33am UTC](https://www.ruby-forum.com/t/re-random-gauss-numbers-and-other-distributions-of-rando/49124 "2005-11-30T10:33:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nuralanur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/90db22/32.png) [@Nuralanur](https://www.ruby-forum.com/u/Nuralanur)\
**Post date:** [November 30, 2005, 10:33am UTC](https://www.ruby-forum.com/t/re-random-gauss-numbers-and-other-distributions-of-rando/49124/1 "2005-11-30T10:33:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nuralanur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/90db22/32.png) [@Nuralanur](https://www.ruby-forum.com/u/Nuralanur)\
**Post date:** [November 30, 2005, 1:51pm UTC](https://www.ruby-forum.com/t/re-random-gauss-numbers-and-other-distributions-of-rando/49124/2 "2005-11-30T13:51:40Z")

</div>

On 11/30/05, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Nuralanur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/90db22/32.png) [@Nuralanur](https://www.ruby-forum.com/u/Nuralanur)\
**Post date:** [November 30, 2005, 5:02pm UTC](https://www.ruby-forum.com/t/re-random-gauss-numbers-and-other-distributions-of-rando/49124/3 "2005-11-30T17:02:40Z")

</div>

On Nov 30, 2005, at 1:28 AM, removed\_email\_address@domain.invalid 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

---

<div class="post-metadata">

**Author:** ![Nuralanur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/90db22/32.png) [@Nuralanur](https://www.ruby-forum.com/u/Nuralanur)\
**Post date:** [December 5, 2005, 11:12pm UTC](https://www.ruby-forum.com/t/re-random-gauss-numbers-and-other-distributions-of-rando/49124/4 "2005-12-05T23:12:54Z")

</div>

Hi!

At Thu, 1 Dec 2005 01:01:39 +0900, Stephen W. 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

---

<div class="post-metadata">

**Author:** ![Nuralanur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/90db22/32.png) [@Nuralanur](https://www.ruby-forum.com/u/Nuralanur)\
**Post date:** [December 6, 2005, 3:34pm UTC](https://www.ruby-forum.com/t/re-random-gauss-numbers-and-other-distributions-of-rando/49124/5 "2005-12-06T15:34:34Z")

</div>

Take a look at this website. Shouldn’t be hard at all to implement in  
ruby.

> **[Generating Gaussian Random Numbers, Taygeta Scientific Inc.](https://www.taygeta.com/random/gaussian.html)**
>
> We provide servies in scientific computing, mathematics, simulation, data analysis and embedded system development

\_Kevin
