rand() v. rand(0.1) ?

F

Florian Frank

7stud said:
Is there any difference between calling rand() and rand(0.1)?
------------------------------------------------------------ Kernel#rand
rand(max=0) => number
 
C

Chad Perrin

------------------------------------------------------------ Kernel#rand
rand(max=0) => number

Speaking of which . . . obviously rand() doesn't produce a truly random
number, but it's reasonably close for some purposes. I'm curious about
just how far off it is, though -- because I'm curious about how
appropriate it is to use to simulate dice-rolling for gaming software (in
the "roleplaying game" sense of the term "gaming") in Ruby's
implementation. I'd prefer some kind of a general feel for it before I
write software to statistically analyze the output of millions of
iterations of rand() evaluations.
 
C

Chad Perrin

Hi,

In message "Re: rand() v. rand(0.1) ?"

|Speaking of which . . . obviously rand() doesn't produce a truly random
|number, but it's reasonably close for some purposes. I'm curious about
|just how far off it is, though -- because I'm curious about how
|appropriate it is to use to simulate dice-rolling for gaming software (in
|the "roleplaying game" sense of the term "gaming") in Ruby's
|implementation.

It uses Mersenne Twister algorithm which has a period of 2**19937-1.

Excellent! Thank you for the quick and informative response.
 
M

Morton Goldberg

That was my analysis too, however pickaxe2 has some code on p. 138
that
calls rand(0.1).

You've found a bug in the Pickaxe book. I'm guessing but I suspect that

sleep(rand(0.1))

should be

sleep(0.1 * rand)

That is, I think the idea was to sleep in the range 0.0 to 0.1
seconds, not 0.0 to 1.0 seconds.

Regards, Morton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top