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

jessejohnson147

macrumors newbie
Original poster
Jun 5, 2009
29
0
What I am trying to achieve is to have a bg image that will randomize when the user clicks the randomize button, but finding a good randomize code that I could use to learn has been hard to come by. Does anyone know any good resources for a random generator code?

Thanks,
 
it really all depends how you define "good".
all the numbers you generate will be pseudo-random. getting real random numbers isn't possible with a normal computer as far as I know.

I found the following to be working ... ok ... for me. If you don't need it for some security stuff it should do the trick:
Code:
int randomNumber = arc4random()%maximumNumber;
whereas maximum number is ... well ... the maximum you want your random number to be. if you don't need a max just ommit that part and you should get something between 0 and INT_MAX
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.