Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random numbers

Status
Not open for further replies.

skata

Programmer
Joined
Oct 25, 2002
Messages
7
Location
US
I want to get a completely random number without having the user input a seed or range. Will someone tell me how to do this?
 
#include <time.h>
#include <stdlib.h> // or wherever srand and rand live

srand (time (0));

It will initialize the random number based on the current time. So unless you have a battery that is not working, and run the same sequence with the same timing everytime, you will get a different seed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top