Question About Random?

Reply

Join Date: Nov 2009
Posts: 1
Reputation: spatel14 is an unknown quantity at this point 
Solved Threads: 0
spatel14 spatel14 is offline Offline
Newbie Poster

Question About Random?

 
0
  #1
27 Days Ago
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!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 362
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 46
gerard4143's Avatar
gerard4143 gerard4143 is offline Offline
Posting Whiz
 
0
  #2
27 Days Ago
Originally Posted by spatel14 View 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!
I would lookup random or srandom...for pseudo random functions in C
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: Arcaiz is an unknown quantity at this point 
Solved Threads: 1
Arcaiz's Avatar
Arcaiz Arcaiz is offline Offline
Newbie Poster
 
0
  #3
27 Days Ago
You could use rand() or srand() for it. Read the manual in google for the details.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: ssathyaraajj is an unknown quantity at this point 
Solved Threads: 0
ssathyaraajj ssathyaraajj is offline Offline
Newbie Poster
 
0
  #4
26 Days Ago
Originally Posted by spatel14 View 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!
"srand()/rand()" isn't exactly the most sophisticated random number generator in the world, but it *should* work for your purposes.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,652
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 723
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess
 
2
  #5
26 Days Ago
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 18
Reputation: Chilton is an unknown quantity at this point 
Solved Threads: 2
Chilton Chilton is offline Offline
Newbie Poster
 
0
  #6
25 Days Ago
You can try seeding the random number generator with a call to time().
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC