Advertisement

random number generation

Started by February 08, 2000 08:04 AM
4 comments, last by shad 24 years, 10 months ago
How do I generate a random number between 0 and x in windows?
rand() % x
Advertisement
rand() %(x+1), actually
He asked "between" not "inclusive":

rand() % 5 : 0 -> 4 // there are 5 numbers here
rand() % (5 + 1) : 0 -> 5 // there are 6 numbers here

Actually, use something like

( (float)rand() / (RAND_MAX + 1) ) * N

to generate # between 0-N

This would give a more distributed random number than the rand()%N
and this has to do with isometric, how...?

This topic is closed to new replies.

Advertisement