Forum: Ruby Strange behaviour of Rb-Gsl random numbers (Windows one-clic

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 unknown (Guest)
on 2006-06-07 00:28
(Received via mailing list)
Dear all,

I've installed Rb-gsl for the Ruby-one click installer,
and tried GSL::Rng.new.uniform to get a random number.
This works, but always gives the same number:



require "gsl"

res=[]
for k in  0..20
res<<GSL::Rng.new.uniform
end
p res

>res=[0.999741748906672, 0.999741748906672, 0.999741748906672,
0.999741748906672, 0.999741748906672, 0.999741748906672,
0.999741748906672,
0.999741748906672, 0.999741748906672, 0.999741748906672,
0.999741748906672,
0.999741748906672, 0.999741748906672, 0.999741748906672,
0.999741748906672,
0.999741748906672, 0.999741748906672, 0.999741748906672,
0.999741748906672,
0.999741748906672, 0.999741748906672]

Why ?

Thank you,

best regards,

Axel
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-06-07 00:38
(Received via mailing list)
On Wed, 7 Jun 2006 Nuralanur@aol.com wrote:

> res=[]
> 0.999741748906672, 0.999741748906672]
>
> Why ?

you have to specify what kind of random number generator you want.  try
this

   irb(main):023:0> r = GSL::Rng.alloc Rng::TAUS, 1
   => GSL::Rng

   irb(main):024:0> Array.new(20).map{ r.uniform }
   => [0.186914603225887, 0.951039797859266, 0.545435771113262,
   0.0746261349413544, 0.22921886225231, 0.522971297148615,
0.0927675529383123,
   0.511819139821455, 0.339204750722274, 0.793815617682412,
0.00488071935251355,
   0.342924846103415, 0.296411268645898, 0.933765491936356,
0.208252872806042,
   0.0223858365789056, 0.256050609983504, 0.684481433359906,
0.983118103351444,
   0.441584395710379]

http://rb-gsl.rubyforge.org/rng.html

regards.

-a
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-06-07 00:50
(Received via mailing list)
On Wed, 7 Jun 2006 Nuralanur@aol.com wrote:

> res=[]
> 0.999741748906672, 0.999741748906672]
>
> Why ?
>
> Thank you,
>
> best regards,
>
> Axel

i confirmed it - this works on my windows box:


   jib:~ > ruby -r gsl -e'  include GSL;  r = Rng.alloc Rng::TAUS, 1;  p
Array.new(20).map!{ r.uniform }  '

   [0.186914603225887, 0.951039797859266, 0.545435771113262,
0.0746261349413544,
   0.22921886225231, 0.522971297148615, 0.0927675529383123,
0.511819139821455,
   0.339204750722274, 0.793815617682412, 0.00488071935251355,
0.342924846103415,
   0.296411268645898, 0.933765491936356, 0.208252872806042,
0.0223858365789056,
   0.256050609983504, 0.684481433359906, 0.983118103351444,
0.441584395710379]


regards.

-a
This topic is locked and can not be replied to.