Click to See Complete Forum and Search --> : restricting random

04-02-2002, 05:24 PM
i need to create a random whole number between two numbers such as,
between 7 and 25.

does anyone know how this is done?


04-03-2002, 02:55 AM
to create a random integer between 7 and 25.

Math.random() returns a random # between 0 and .99999
so first we stretch the span
which changes the span to 0 to 17.9999
so then add 7.5 and chop the decimal.
so this makes the range 7 to 25, just the integers.

in general:
a to b, just the integers


just in case:

are you trying to get something like 6d4+1 ?

because that's different.

six four sided dice plus 1 makes a nice bell curve centered on 16, to get this sort of curve, just add up 6 separately generated a=1,b=4 types, then add 1.

you'll notice a lack of >21 <11 results, try it....