samedi 20 octobre 2018

How can I check if a number is equal to a random number between 1 and the value of the number?

I have a variable phrase.points that can have a value of between 1 and x. What I would like to do is something like this:

if (phrase.points == random number generated between 1 and x) 
     return;

so if:

phrase.points == 1 and random number == 1 return
phrase.points == 2 and random number == 1 don't return
phrase.points == 2 and random number == 2 return
phrase.points == 3 and random number == 1 don't return
phrase.points == 3 and random number == 2 don't return
phrase.points == 3 and random number == 3 return

Can anyone give me a suggestion on how could achieve this?




Aucun commentaire:

Enregistrer un commentaire