Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 9, 2008, 11:31 PM   #1
MDMstudios
macrumors member
 
Join Date: Mar 2008
random()

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.
MDMstudios is offline   0 Reply With Quote
Old Apr 9, 2008, 11:38 PM   #2
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
use randomize() to use a clock-based seed.

-Lee
lee1210 is offline   0 Reply With Quote
Old Apr 9, 2008, 11:39 PM   #3
cruzrojas
macrumors member
 
Join Date: Mar 2007
Location: 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.
__________________
Systems: MBP SantaRosa, 15', 160Gb@7200 rpm HD; G4 mac mini
iPod: ipod nano 1Gb, 1st gen, touch 16 Gb, 2nd gen
Blog: chuyandmac.blogspot.com
cruzrojas is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Random Resets jlhx iOS 7 8 Dec 1, 2013 07:43 AM
Random Apple ID kousha OS X Mavericks (10.9) 2 Nov 19, 2013 10:21 AM
iPhone: Random Crashing cclloyd Jailbreaks and iOS Hacks 5 Feb 8, 2013 12:26 PM
MBP 2010 random/not so random crashes? Kobaine MacBook Pro 0 Jan 3, 2013 04:10 PM
Random sleep Chrisspy MacBook Pro 0 Nov 27, 2012 10:19 AM

Forum Jump

All times are GMT -5. The time now is 04:23 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC