lundi 30 novembre 2015

New arc4random()%x; different from Previous number

I have this line of code to calculate a random number:

    myRand = arc4random()%24; //0:23

What's the most efficient way of adding to this in order for this not to generate the same number it previously generated.

I'm not trying to shuffle all 24, as I do want repeats, just preferably not 2 of the same number directly after each other...

I thought of storing the previous number separately, then comparing it and if matching, just do it again, but I couldn't figure out away if for example the same number came out 3 times in a row... Unlikely I know, but it's possible.

Thanks.




Aucun commentaire:

Enregistrer un commentaire