dimanche 29 mai 2016

Obtaining Random Numbers from irregular Ranges

I want to get a random number from (0,2,6,8,4) or such ranges. Currently I loop till I get appropriate Num.

boxNum = getRandomNum(0, 8);

  while (boxNum == 1 || boxNum == 3 || boxNum == 5 || boxNum == 7))
    boxNum = getRandomNum(0, 8);

Is there any other way to do this?? The while loop crashes the page after some turns.




Aucun commentaire:

Enregistrer un commentaire