random number generation
He asked "between" not "inclusive":
rand() % 5 : 0 -> 4 // there are 5 numbers here
rand() % (5 + 1) : 0 -> 5 // there are 6 numbers here
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
( (float)rand() / (RAND_MAX + 1) ) * N
to generate # between 0-N
This would give a more distributed random number than the rand()%N
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement