The random number function always generates a number between zero and one. You can convert this to a random number in any range by a suitable combination of multiplications and additions. For example, if you want a random number between zero and ten, multiply the generated random number by 10. If you want a random number between one and ten, multiply the generated random number by 9 and then add 1.
If you want to simulate the roll of a six-sided die, multiply the generated random number by 6, add 1, and ignore the fractional portion. This will give you a 1, 2, 3, 4, 5, or 6 with more-or-less equal probability.
642 views
Usually answered in minutes!
×