Very short snippet: iPhone, random numbers
Friday, October 9th, 2009 If you need to generate random numbers in an application from the Apple iPhone you have to put Objective-C, because it proposes no class for this purpose. The solution is that proposed by the C: rand(), srand(), random(), srandom() e arc4random()
Of all the most popular is definitely arc4random() because it does not require any special initialization or seeding functions, returning a good value "random", we could say that it is self-inizializzante.
- / / Generate a random number from 0 to 99
- arc4random ( ) % 100 ; int rnd = arc4random ()% 100;
- / / Generate a random number from 20 to 50
- arc4random ( ) % 51 ) + 20 ; int rnd = (arc4random ()% 51) + 20;













There are no comments for this post
Leave a comment