Simple question about rand()

Non-platform specific questions.

Simple question about rand()

Postby Troodon » Sat Feb 25, 2006 8:05 am

Is this:
rand(1*10)
meaning 1 to 10
And is this:
rand(2*10)
meaning 2 to 10 or 1 to 20?
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Re: Simple question about rand()

Postby Fuzzy » Sat Feb 25, 2006 10:04 am

tekdino wrote:Is this:
rand(1*10)
meaning 1 to 10
And is this:
rand(2*10)
meaning 2 to 10 or 1 to 20?


0 to 19 i believe. use rand(20)+1 to get 1-20. rand(19)+2 would be 2-21.

If you want to get 2-20, use (rand(10)+1)+(rand(10)+1)

using a simple rand statement is going to get you a flat probability; equal chances of all numbers. once you start adding them together, it creates a bell curve with the average being favoured.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest