Archived

This topic is now archived and is closed to further replies.

Dan Blokker

Newbie Question About Rand()

Recommended Posts

Hi all, I''m trying to get a random number between 1 and 100 with rand but I don''t know how to change the RAND_MAX value, or at least I think that is what I need to change. I try to change it just by putting RAND_MAX = 100 in my program but this just gives me errors. Please help me. I know its probably something easy but I have know idea. Thanks Dan

Share this post


Link to post
Share on other sites
There''s no max in rand, take this peace of code for example:
float a = rand()%100
this vill give you a random number between
0-99 or maybe it was 0-100 or 1-100, well you''ll probably find that out yourself.

Share this post


Link to post
Share on other sites
Oh I must have misinterpreted the MSDN. This is what it says.

"The rand function returns a pseudorandom integer in the range 0 to RAND_MAX. Use the srand function to seed the pseudorandom-number generator before calling rand."

So I assumed that I had to change RAND_MAX to set what the maxime number could be.


Dan

Share this post


Link to post
Share on other sites