Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MDMstudios

macrumors member
Original poster
Mar 18, 2008
36
0
I'm making a program that needs to produce a different random number each time the program is used, the problem is when I use the random() function, it produces the same random number each time I use it.
 

cruzrojas

macrumors member
Mar 26, 2007
67
0
USA
You need to seed your program with srandom(unsigned long seed), if you use the same seed in 2 different runs you will get the same result every time, which is useful for debugging. Once you want to deploy your application you can use the computer time as the seed and this will produce different seed every time.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.