Can You Exclude a Specific Number When Generating Random Numbers in Mathematica?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
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.