Im trying to do something but it requires the use of random numbers and i can make random numbers but i want them in a certain range eg 1-10
Printable View
Im trying to do something but it requires the use of random numbers and i can make random numbers but i want them in a certain range eg 1-10
my_number = (rnd() * (max_val - min_val + 1)) + min_val
in this particular case:
my_number = (Rnd() * (10 - 1)) + 1
ERROR!!This only gives random numbers 1 to 9.Quote:
my_number = (Rnd() * (10 - 1)) + 1
The correct formula is :-
Code:MyNumber = Int(Rnd() * 10) + 1
oops.. I forgot to carry across the +1!
it should have been :
my_number = (Rnd() * (10 - 1 + 1)) + 1
(which is the same as you said!)
Thanx very much