M
Michael B Allen
Someone once posted the following macro on clc:
#define randint(a,b) (a)+(((b)-(a)+1)*(float)rand()/RAND_MAX)
Unfortunately it's flawed. If rand() returns RAND_MAX the result can be
one larger than b.
So can someone provide a *proper* macro (or function) that returns a
random integer between (actually in) a range of values? For example
randint(0, 999) could return:
0
10
777
999
Mike
#define randint(a,b) (a)+(((b)-(a)+1)*(float)rand()/RAND_MAX)
Unfortunately it's flawed. If rand() returns RAND_MAX the result can be
one larger than b.
So can someone provide a *proper* macro (or function) that returns a
random integer between (actually in) a range of values? For example
randint(0, 999) could return:
0
10
777
999
Mike