|
-
Sep 30th, 2000, 02:38 PM
#1
Hi, I have just started to teach myself C++ programming for DOS (I use the DJGPP compiler). I need to find a way to generate random numbers (its for a number-guessing game that I have set myself a task to create!). I need the numbers to be within a certain range for example 0-10000.
I cannot seem to make any of the srand() or rand() commands work.
Which headers do i need to #include ?
Greatful for any enlightenment 
It's a great language to learn isn't it, very satisfying when it works (not often for me).
-
Sep 30th, 2000, 04:10 PM
#2
Frenzied Member
Try stdlib.h, I think that's where the rand() function is defined.
Harry.
"From one thing, know ten thousand things."
-
Sep 30th, 2000, 04:13 PM
#3
Frenzied Member
Oh yeah, and to get one in a range, use this:
randomNumber = rand % (max-min) + min
where max and min define the range of values you want.
Harry.
"From one thing, know ten thousand things."
-
Sep 30th, 2000, 05:10 PM
#4
Monday Morning Lunatic
srand() seeds the random number. Basically, it allows the random numbers to be more "random". If you seed it with something like the current time, you're much more likely to get different numbers.
Then call rand() as normal.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 1st, 2000, 03:59 AM
#5
thanks guys ill give it a try.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|