Friday, September 28, 2012

Playing with Random() in objective c



1)//Generating a simple random number

int random = random();

2)//A list of random number

int generated;

for (int i =0; i<10 br="br" i="i">generated = abs(100000*(random()));
NSLog(@”New Random Key: %d”,generated);
}

3)//Real Randomness :

srandom(time(NULL));

int generated;

for (int i =0; i<10 br="br" i="i">generated = abs(100000*(random()));
NSLog(@”New Random Key: %d”,generated);
}

4)Best One

arc4random()

It seems to be more popular and improves generation with unique-randoms.

No comments:

Post a Comment