[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: Why am I not getting the results I expect...
+ display_article_number = 1 + (int) (((float) num_of_arts) * random() /
+ (RAND_MAX+1.0));
[snip]
+
+ I expect this piece of code to generate a random number between 1 and 24.
+ But it also generates number > 24. What am I doing wrong? I got the algo
+ to generate a random number between 1 and n from the manpage for rand()
+ (not random()).
Does not seem to be the case here. The outpt is as expected. BTW, what is
the processor type? Is it because of the same "lower-order bits" thing as
mentioned in rand man page (arch dependence... huh).
Sharad.