May 8th, 2012, 08:20 PM
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
Yes, so what is the best solution.
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] are essential for python code!