PDA

Click to See Complete Forum and Search --> : Random Number


invitro
Aug 18th, 2000, 06:01 PM
Does anybody know how to make a random number thats not between 1 - 0?
Im traying to make a simple game to teach myself, and im traying to generate a random number from 1 - 11.

Thanks!

noone
Aug 18th, 2000, 08:41 PM
Once you have a random number that is between 0-1 you multiply it by 11, round down, and add one.:

double tempValue = Math.random() * maxValue;
int value = (int) Math.floor(tempValue) + 1;

Thats acually a bit more code then you need.

invitro
Aug 19th, 2000, 07:50 PM
Works great, thanks!