944,139 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 494
  • C RSS
Nov 3rd, 2009
0

Question About Random?

Expand Post »
How do I generate random numbers in C? The user doesn't enter anything, I'm just looking for a way to generate random numbers every time I run the program.

Thanks guys!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
spatel14 is offline Offline
1 posts
since Nov 2009
Nov 3rd, 2009
0
Re: Question About Random?
Click to Expand / Collapse  Quote originally posted by spatel14 ...
How do I generate random numbers in C? The user doesn't enter anything, I'm just looking for a way to generate random numbers every time I run the program.

Thanks guys!
I would lookup random or srandom...for pseudo random functions in C
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,198 posts
since Jan 2008
Nov 3rd, 2009
0
Re: Question About Random?
You could use rand() or srand() for it. Read the manual in google for the details.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Arcaiz is offline Offline
12 posts
since Oct 2009
Nov 4th, 2009
0
Re: Question About Random?
Click to Expand / Collapse  Quote originally posted by spatel14 ...
How do I generate random numbers in C? The user doesn't enter anything, I'm just looking for a way to generate random numbers every time I run the program.

Thanks guys!
"srand()/rand()" isn't exactly the most sophisticated random number generator in the world, but it *should* work for your purposes.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ssathyaraajj is offline Offline
1 posts
since Nov 2009
Nov 4th, 2009
2
Re: Question About Random?
>I would lookup random or srandom...for pseudo random functions in C
Neither of which are standard functions, meaning unless the OP has the same compiler you do, the chances of your suggestion working are somewhat slim. srand and rand are the standard functions for seeding and generating random numbers.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 6th, 2009
0
Re: Question About Random?
You can try seeding the random number generator with a call to time().
Reputation Points: 34
Solved Threads: 16
Junior Poster
Chilton is offline Offline
106 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: please help in following data structure programs
Next Thread in C Forum Timeline: Bowling program (wrong scores)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC