By default, the parameterless constructor of the System.Random class (which is 
what we're using) uses the system time as the initial seed.  Every time you ask 
for a random number, we create a new Random object, and in a tight loop like 
yours, they'll probably all get the same seed.

We should probably create a single Random object the first time that one is 
requested and store it in the RubyContext.

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Johan Danforth
Sent: Sunday, July 06, 2008 7:28 AM
To: [email protected]
Subject: [Ironruby-core] rand() needs a seed?

I'm a noob Ruby user, but IronRuby behaves different from other Ruby 
implementations that I've tried, in IronRuby (rev 121) this code:

100.times {p rand(100)}

Often returns the same value for (almost) all iterations, like this:

2
2
2
2
2
2
2
2
...and so on...

Works as designed? Need to seed it or something?

/Johan
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to