RandomInt
RandomInt
RandomInt[ { n1, n2 }, n3 ] selects one or more random integer numbers from a range.
Usages
RandomInt[{ n1, n2 }]
RandomInt[{ n1, n2 }] returns an integer greater than or equal to n1 and smaller than or equal to n2.
| Example | in | out |
|---|---|---|
A randomly selected number between 1 and 5. |
RandomInt[{1,5}] |
3 |
RandomInt[ { n1, n2 }, n3 ]
RandomInt[ { n1, n2 }, n3 ] returns a list of length n3 with each element an integer greater than or equal to n1 and smaller than or equal to n2. Note that the result may contain duplicates.
| Example | in | out |
|---|---|---|
A list of 3 randomly selected values between 1 and 5. |
RandomInt[ { 1,5 }, 3 ] |
{ 3, 5, 3 } |
A list of n randomly selected values between x and y, where n is defined as 2, x is defined as 3 and y is defined as 10 in the script. |
RandomInt[{x, y}, n] |
{6, 3} |
Options
AllowDuplicates
AllowDuplicates prevents the same number from being drawn more than once if set to False.
| Syntax | Example |
|---|---|
RandomInt[{n1, n2}, n3, AllowDuplicates=>False] |
RandomInt[{1, 10},5, AllowDuplicates=>False] |
Exclude
Exclude prevents the numbers m1, m2, ... from being selected.
| Syntax | Example |
|---|---|
RandomInt[{n1,n2},Exclude=>{m1, m2, ..., mk}] |
RandomInt[{-5,5}, Exclude=>{0,1}] |