[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Separate random number generators?

Bart Braem

1/22/2009 10:38:00 AM

For simulation work, I want to use multiple, independent random number
generators. Does anyone know up to date implementations?

I found randomr but that is inactive sinds 2001 and clearly marked
alpha (http://rubyvm.sourceforge.net/subproject...)
I also found some projects from MoonWolf from 2004 but his site
(www.moonwolf.com, see e.g. http://raa.ruby-lang.org/project/rando...)
is offline. Which makes it hard to get to the code.
There is a generator that uses certain sites, but that is not really
an option.
I am now going to look at the isaac gem, but its version number 0.0.2
does not make me feel very happy.

Did anyone find better implemenations of PRNGs?
17 Answers

Lars Christensen

1/22/2009 11:13:00 AM

0

On Jan 22, 11:38 am, Bart Braem <bart.br...@gmail.com> wrote:
> For simulation work, I want to use multiple, independent random number
> generators. Does anyone know up to date implementations?

What do you mean by independent RNG? Numbers drawn from a single RNG
are usually independent enough.

Do you mean separate deterministic PRNGs with fixed seeds for
reproducible sequences? Then take a look at this Ruby Quiz:

http://www.splatbang.com/rubyquiz/quiz.rhtml?id=173_Not...

Bart Braem

1/22/2009 11:37:00 AM

0

On Jan 22, 12:13 pm, Lars Christensen <lar...@belunktum.dk> wrote:
> On Jan 22, 11:38 am, Bart Braem <bart.br...@gmail.com> wrote:
>
> > For simulation work, I want to use multiple, independent random number
> > generators. Does anyone know up to date implementations?
>
> What do you mean by independent RNG? Numbers drawn from a single RNG
> are usually independent enough.
>
> Do you mean separate deterministic PRNGs with fixed seeds for
> reproducible sequences? Then take a look at this Ruby Quiz:
>
> http://www.splatbang.com/rubyquiz/quiz.rhtml?id=173_Not...

I indeed mean separate deterministic PRNGs with fixed seeds for
reproducible sequences. Interesting to see this was a Ruby Quiz! Are
there solutions without the use of DRb and other libraries?

Thanks for your fast reply!

Chris Lowis

1/22/2009 11:59:00 AM

0

Bart Braem wrote:
> On Jan 22, 12:13�pm, Lars Christensen <lar...@belunktum.dk> wrote:
>>
>> http://www.splatbang.com/rubyquiz/quiz.rhtml?id=173_Not...
>
> I indeed mean separate deterministic PRNGs with fixed seeds for
> reproducible sequences. Interesting to see this was a Ruby Quiz! Are
> there solutions without the use of DRb and other libraries?
>
> Thanks for your fast reply!

I know this doesn't meet your criteria of independence from other
libraries, but the GSL (GNU Scientific Library) has a number (of
different algorithms for seeded random number generation. It's fairly
easy to call these functions from Ruby using the rb-gsl
(http://rb-gsl.ruby...) bindings. Here's some examples:
http://rb-gsl.ruby...rng.html

I've also written a bit about that in the past on my blog
(http://blog.chrisl...).

Hope this helps,

Chris
--
Posted via http://www.ruby-....

James Gray

1/22/2009 1:20:00 PM

0

On Jan 22, 2009, at 5:39 AM, Bart Braem wrote:

> On Jan 22, 12:13 pm, Lars Christensen <lar...@belunktum.dk> wrote:
>> On Jan 22, 11:38 am, Bart Braem <bart.br...@gmail.com> wrote:
>>
>>> For simulation work, I want to use multiple, independent random
>>> number
>>> generators. Does anyone know up to date implementations?
>>
>> What do you mean by independent RNG? Numbers drawn from a single RNG
>> are usually independent enough.
>>
>> Do you mean separate deterministic PRNGs with fixed seeds for
>> reproducible sequences? Then take a look at this Ruby Quiz:
>>
>> http://www.splatbang.com/rubyquiz/quiz.rhtml?id=173_Not...
>
> I indeed mean separate deterministic PRNGs with fixed seeds for
> reproducible sequences. Interesting to see this was a Ruby Quiz! Are
> there solutions without the use of DRb and other libraries?

Sure. See the first solution link on that page (also shown in the
quiz write-up).

James Edward Gray II

Bart Braem

1/23/2009 2:08:00 PM

0

On Jan 22, 2:20 pm, James Gray <ja...@grayproductions.net> wrote:
> On Jan 22, 2009, at 5:39 AM, Bart Braem wrote:
>
>
>
> > On Jan 22, 12:13 pm, Lars Christensen <lar...@belunktum.dk> wrote:
> >> On Jan 22, 11:38 am, Bart Braem <bart.br...@gmail.com> wrote:
>
> >>> For simulation work, I want to use multiple, independent random  
> >>> number
> >>> generators. Does anyone know up to date implementations?
>
> >> What do you mean by independent RNG? Numbers drawn from a single RNG
> >> are usually independent enough.
>
> >> Do you mean separate deterministic PRNGs with fixed seeds for
> >> reproducible sequences? Then take a look at this Ruby Quiz:
>
> >>http://www.splatbang.com/rubyquiz/quiz.rhtml?id=173_Not...
>
> > I indeed mean separate deterministic PRNGs with fixed seeds for
> > reproducible sequences. Interesting to see this was a Ruby Quiz! Are
> > there solutions without the use of DRb and other libraries?
>
> Sure.  See the first solution link on that page (also shown in the  
> quiz write-up).
>
> James Edward Gray II

The first solution is of course not that efficient, I will be
generating lots of random numbers. I'm going to take a look at ruby-
gsl, the ISAAC library gives strange results...

Thanks for your help!

Lars Christensen

1/23/2009 2:34:00 PM

0

On Jan 23, 3:07 pm, Bart Braem <bart.br...@gmail.com> wrote:
> On Jan 22, 2:20 pm, James Gray <ja...@grayproductions.net> wrote:
>
>
>
> > On Jan 22, 2009, at 5:39 AM, Bart Braem wrote:
>
> > > On Jan 22, 12:13 pm, Lars Christensen <lar...@belunktum.dk> wrote:
> > >> On Jan 22, 11:38 am, Bart Braem <bart.br...@gmail.com> wrote:
>
> > >>> For simulation work, I want to use multiple, independent random  
> > >>> number
> > >>> generators. Does anyone know up to date implementations?
>
> > >> What do you mean by independent RNG? Numbers drawn from a single RNG
> > >> are usually independent enough.
>
> > >> Do you mean separate deterministic PRNGs with fixed seeds for
> > >> reproducible sequences? Then take a look at this Ruby Quiz:
>
> > >>http://www.splatbang.com/rubyquiz/quiz.rhtml?id=173_Not...
>
> > > I indeed mean separate deterministic PRNGs with fixed seeds for
> > > reproducible sequences. Interesting to see this was a Ruby Quiz! Are
> > > there solutions without the use of DRb and other libraries?
>
> > Sure.  See the first solution link on that page (also shown in the  
> > quiz write-up).
>
> > James Edward Gray II
>
> The first solution is of course not that efficient, I will be
> generating lots of random numbers. I'm going to take a look at ruby-
> gsl, the ISAAC library gives strange results...
>
> Thanks for your help!

I do think that my own solution (last on the page) is efficient, but i
can't vouch for the statistical properties (it reseeds the Mersenne
Twister in Ruby every time a number is drawn, although randomly).

Bart Braem

1/23/2009 2:39:00 PM

0

On Jan 23, 3:07 pm, Bart Braem <bart.br...@gmail.com> wrote:
> On Jan 22, 2:20 pm, James Gray <ja...@grayproductions.net> wrote:
>
>
>
> > On Jan 22, 2009, at 5:39 AM, Bart Braem wrote:
>
> > > On Jan 22, 12:13 pm, Lars Christensen <lar...@belunktum.dk> wrote:
> > >> On Jan 22, 11:38 am, Bart Braem <bart.br...@gmail.com> wrote:
>
> > >>> For simulation work, I want to use multiple, independent random  
> > >>> number
> > >>> generators. Does anyone know up to date implementations?
>
> > >> What do you mean by independent RNG? Numbers drawn from a single RNG
> > >> are usually independent enough.
>
> > >> Do you mean separate deterministic PRNGs with fixed seeds for
> > >> reproducible sequences? Then take a look at this Ruby Quiz:
>
> > >>http://www.splatbang.com/rubyquiz/quiz.rhtml?id=173_Not...
>
> > > I indeed mean separate deterministic PRNGs with fixed seeds for
> > > reproducible sequences. Interesting to see this was a Ruby Quiz! Are
> > > there solutions without the use of DRb and other libraries?
>
> > Sure.  See the first solution link on that page (also shown in the  
> > quiz write-up).
>
> > James Edward Gray II
>
> The first solution is of course not that efficient, I will be
> generating lots of random numbers. I'm going to take a look at ruby-
> gsl, the ISAAC library gives strange results...
>
> Thanks for your help!

Do not use ISAAC, running this simple test:

rng = Crypt::ISAAC.new
res = Hash.new()
1.upto(100000) do |i|
random = rng.rand
larger = (random * 10).to_i
res[larger] ||= 0
res[larger] += 1
end
1.upto(10) do |i|
puts "hits for #{i}: #{res[i]}"
end

Shows a large bias towards numbers below 0.4, unless I have an error
in this simple script of course.
rb-gsl gives problems with installation, I am going to try the Drb
solution.

Bart Braem

1/23/2009 3:00:00 PM

0

On Jan 23, 3:34 pm, Lars Christensen <lar...@belunktum.dk> wrote:
> On Jan 23, 3:07 pm, Bart Braem <bart.br...@gmail.com> wrote:
>
>
>
> > On Jan 22, 2:20 pm, James Gray <ja...@grayproductions.net> wrote:
>
> > > On Jan 22, 2009, at 5:39 AM, Bart Braem wrote:
>
> > > > On Jan 22, 12:13 pm, Lars Christensen <lar...@belunktum.dk> wrote:
> > > >> On Jan 22, 11:38 am, Bart Braem <bart.br...@gmail.com> wrote:
>
> > > >>> For simulation work, I want to use multiple, independent random  
> > > >>> number
> > > >>> generators. Does anyone know up to date implementations?
>
> > > >> What do you mean by independent RNG? Numbers drawn from a single RNG
> > > >> are usually independent enough.
>
> > > >> Do you mean separate deterministic PRNGs with fixed seeds for
> > > >> reproducible sequences? Then take a look at this Ruby Quiz:
>
> > > >>http://www.splatbang.com/rubyquiz/quiz.rhtml?id=173_Not...
>
> > > > I indeed mean separate deterministic PRNGs with fixed seeds for
> > > > reproducible sequences. Interesting to see this was a Ruby Quiz! Are
> > > > there solutions without the use of DRb and other libraries?
>
> > > Sure.  See the first solution link on that page (also shown in the  
> > > quiz write-up).
>
> > > James Edward Gray II
>
> > The first solution is of course not that efficient, I will be
> > generating lots of random numbers. I'm going to take a look at ruby-
> > gsl, the ISAAC library gives strange results...
>
> > Thanks for your help!
>
> I do think that my own solution (last on the page) is efficient, but i
> can't vouch for the statistical properties (it reseeds the Mersenne
> Twister in Ruby every time a number is drawn, although randomly).

I've tested this setup, with just one RNG. Running my unit tests is
about 5 times slower, unfortunately. I am calling the random number
very often, more than 10.000 times in 10 seconds in a simulation that
uses the standard kernel rand.
I can't afford this slowdown, but it seems as though there are no
other solutions that do not use a pure-ruby library?

Chris Lowis

1/23/2009 3:28:00 PM

0

> rb-gsl gives problems with installation

Out of interest, what kind of problems ?

Chris

--
Posted via http://www.ruby-....

F. Senault

1/23/2009 3:34:00 PM

0

Le 23 janvier 2009 à 15:59, Bart Braem a écrit :

> On Jan 23, 3:34 pm, Lars Christensen <lar...@belunktum.dk> wrote:
>> I do think that my own solution (last on the page) is efficient, but i
>> can't vouch for the statistical properties (it reseeds the Mersenne
>> Twister in Ruby every time a number is drawn, although randomly).
>
> I've tested this setup, with just one RNG. Running my unit tests is
> about 5 times slower, unfortunately. I am calling the random number
> very often, more than 10.000 times in 10 seconds in a simulation that
> uses the standard kernel rand.
> I can't afford this slowdown, but it seems as though there are no
> other solutions that do not use a pure-ruby library?

Can you estimate the number of random numbers you'll need ? Maybe you
could pre-generate sequences of numbers in a few arrays, then patch the
rand method to actually read the array instead of generating the
number ?

The start time and memory consumption will be a lot higher, but maybe it
makes a good compromise ?

Fred
--
I'm broke but I'm happy, I'm poor but I'm kind
I'm short but I'm healthy, yeah
I'm high but I'm grounded, I'm sane but I'm overwhelmed
I'm lost but I'm hopeful, baby (Alanis Morissette, Hand in My Pocket)