vendredi 10 juillet 2015

Ruby, how to get a random number out of a specified group?

If I have a group of numbers like (0,3,6,9) how can I pull a random one out? Just to be clear, what if the group is not a multiple, any random group of numbers, but the chosen one can only be one of those that are in the group, not a range.

How would I need to provide the numbers? In an array? And how to use rand() to only use those specified?




Aucun commentaire:

Enregistrer un commentaire