#define RANDOM_SEED() srandom((unsigned)(mach_absolute_time() & 0xFFFFFFFF))#define RANDOM_NUM() (random())
@interface TestViewController : UIViewController
...
TestViewController.m
#include <mach/mach_time.h>@implementation TestViewController-(int)getRandomNumber{RANDOM_SEED();int randomSelect=RANDOM_NUM()%([yourArray count]-1); // picks a random number in range 0 to countreturn randomSelect;}
No comments:
Post a Comment