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

AI Thread Summary
To generate a list of five random numbers between 1 and 20 while excluding the number 10, one can use a random number generator with a condition. The suggested approach involves using a comparison operator, specifically '!=' which denotes 'not equal'. By creating an array of numbers from 1 to 20 without including 10, the random number generator can then select from this modified array. This technique ensures that the output will not include the excluded number while still providing a random selection from the remaining options.
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.
 

Similar threads

Replies
1
Views
3K
Replies
1
Views
2K
Replies
1
Views
3K
Replies
2
Views
3K
Replies
4
Views
3K
Replies
6
Views
4K
Replies
2
Views
2K
Replies
1
Views
2K
Back
Top