:confused: please some1 can help me in writing a random number generator funtion......generates number from 1-10000...explain it..plz
muadh jamal 0 Newbie Poster
Recommended Answers
Jump to Postnow if you want to give a range you can do it by this syntax
(minimum+rand())%maximum;
for example if you want to generate the numbers between 1 and 10,000 simply do it this way(1+rand())%10000;
Not quite. it's
minimum + (rand() % maximum);
Jump to PostOops.... so it is. Thanks Sannie :D
Jump to PostNot quite, its:
minimum + (rand() % (maximum - minimum));
This will produce random numbers in the range minimum inclusive and maximum exclusive.Not quite, it's
minimum + rand() / (RAND_MAX / (maximum - minimum) + 1 );
To ensure proper distribution.
:twisted:
(sorry, I …
All 10 Replies
qaisu 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
John A 1,896 Vampirical Lurker Team Colleague
Infarction 503 Posting Virtuoso
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
vijayan121 1,152 Posting Virtuoso
Lardmeister 461 Posting Virtuoso
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.