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 strongm 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
Oct 25, 2002
7
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