Excluding a specific number from RandomInteger in Mathematica

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
Sarah rob
Messages
16
Reaction score
0
I am trying to create a list of 5 random numbers between 1 and 20

In[62]:= RandomInteger[{1, 20}, 5]

Out[62]:= {10, 11, 9, 8, 1}

But is it possible to exclude the number 10 from appearing?
 
Physics news on Phys.org
I am more of an R person, but I'm sure there is some kind comparison operator. Something along the lines of

PHP:
if ($x != 10)
   print $x;

You can feed the output of the random number generator into the above code.

The ' != ' means 'not equal'.
 
You could choose a random index to an array of 19 numbers, which includes the numbers 1 thorugh 20, but not 10.