Search code examples
basic4android

Using Rnd with specific numbers rather than a range


Is it possible to generate a random integer from a list of numbers or predefined set - that may not be in order.

For example - generate a random number from 1,2,4,5 (no 3 allowed).


Solution

  • You can create an array with all your predefined set into it, then you fill an integer index with a random number from 0 to the array's length. That should do the trick :)