
May 8th, 2012, 08:20 PM
|
 |
Contributing User
|
|
|
|
Your answer is incorrect. Look here--->
Suppose your maximum random number is 3.
You have a uniform distribution amongst 0, 1, 2, 3.
Now, we want a random number uniformly distributed from 0, 1, 2.
random() % 3 will generate numbers with probability
Code:
number probability
0 1/2
1 1/4
2 1/4
Yes, so what is the best solution.
see thread
http://forums.devshed.com/c-programming-42/rand-code-to-simulate-rand-max-895833.html
Make sure that RAND_MAX+1 converted to double is different from RAND_MAX otherwise use extra logic to remove the case when RAND_MAX == random() .
__________________
[code] Code tags[/code] are essential for python code!
|