7
7stud --
Is there any difference between calling rand() and rand(0.1)?
------------------------------------------------------------ Kernel#rand7stud said:Is there any difference between calling rand() and rand(0.1)?
------------------------------------------------------------ Kernel#rand
rand(max=0) => number
7stud said:Is there any difference between calling rand() and rand(0.1)?
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.
Matthew said:takes a look at the rdoc -
http://www.ruby-doc.org/core/classes/Kernel.html#M005955
its defined as "rand(max=0)"
ie. calling rand() is exactly the same as rand(0)
also it "Converts max to an integer using max1 = max.to_i.abs"
ie. max = 0.1 -> max1 = 0.1.to_i.abs = 0
ie. rand() results in the same behaviour as rand(0.1)
That was my analysis too, however pickaxe2 has some code on p. 138
that
calls rand(0.1).
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.