objective c - Random number generator method -


so have method returns letter (from a-z) creating random number between 1-26 , indexing string array pull out letter. problem not generate new letter when method called. how can generate new letter every time method called, in while loop. here code:

-(nsstring *)alphagenerator{     nsuinteger randomletterinteger = arc4random_uniform(26);     nsarray *alphabet = @[@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z"];     nsstring *alpha = alphabet[randomletterinteger];     return alpha; } 

also, how convert number returned count method number can plug arc4random_uniform method? receive 'incompatible integer pointer inversion initializing...' error. have this:

-(nsuinteger)numofdictions{     nsstring *alpha = [self alphagenerator];     nsuinteger numb = [cuisines[alpha] count];     nsuinteger *randomnumofdictions = arc4random_uniform(numb);     return *randomnumofdictions; } 

these 2 lines:

nsuinteger *randomnumofdictions = arc4random_uniform(numb); return *randomnumofdictions; 

should be:

nsuinteger randomnumofdictions = arc4random_uniform(numb); return randomnumofdictions; 

nsinteger not object type. it's primitive type.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -