Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-07-2009, 08:18 PM   #18 (permalink)
smasher
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

Quote:
Originally Posted by PhillipJames View Post
I am also a new programmer and every time it runs, I get the same order of answers - I have put 6 values in the array and they appear - 6, 3, 5, 5, 6, 2, 3, 5, 2, 4 ......

I can close the sim, recompile and sure enough they appear in this order everytime.

Any ideas?
Yes - random() is actually a pseudorandom number generator. It starts with a "seed" value, and always generates the same set of numbers from that seed. Sooooo... the trick is to pick a different "seed" every time you start the program. The most common way to to do that is by using the current date+time as the seed; then you should get a different sequence every time.

Try this at the beginning of your program; say, in applicationDidFinishLaunching:
srandom (time (0));

BTW, don't get fancy about calling random() more than once, or multiplying two random number to get an even-more-random number, etc - you'd actually be removing randomness, not increasing it.
__________________

Free Games!
smasher is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,736
Threads: 89,191
Posts: 380,535
Top Poster: BrianSlick (7,129)
Welcome to our newest member, wrapsol
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:34 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.