: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 PostHello muadh jamal!
you can simply generate a random number by the function rand() in the stdlib directory. However c++ can't generate true random numbers as they are pseudo-random means having some pattern so we need to seed them for this we use the function srand(), and we must …
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 PostNot quite. it's
minimum + (rand() % maximum);
Not quite, its:
minimum + (rand() % (maximum - minimum));
This will produce random numbers in the range minimum inclusive and maximum exclusive.
;)
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.