# [SOLVED] Random number exclusion?

## Recommended Posts

How do I select a random number between a min and a max, and then after picking that number select another random number between the same min/max excluding the first number I picked?

Example: I want to select 5 random numbers between 1 and 12, and each selection can not be the same. If I select the number 6 the first time I do not want it to be possible to select the number 6 again.

The only way I can see it being done is to compare the later results with the former results and if they are the same, run the random number generator again.. but then is it still truely random? I am no mathmatician so I have no idea... but it does need to be completely random. Does picking an already picked number, tossing it back, and selecting again count as random?

Edited by SkybotGaming

Perfect, thanks.

##### Share on other sites

If you require the full range of numbers between a max and min value to be arranged in random order then you could also do something like this:

```#include <Array.au3>

_Example()

Func _Example()
Local \$aArray[100]
For \$i = 0 to 99
\$aArray[\$i] = \$i
Next

_ArrayShuffle(\$aArray)
_ArrayDisplay(\$aArray)
EndFunc

Func _ArrayShuffle(ByRef \$aArray)
If IsArray(\$aArray) = 0 Or UBound(\$aArray, 0) > 1 Then Return SetError (1)

Local \$vTemp, \$r, \$iBound = UBound(\$aArray) -1
For \$i = 0 To \$iBound
\$r = Random(0, \$iBound, 1)
\$vTemp = \$aArray[\$i]
\$aArray[\$i] = \$aArray[\$r]
\$aArray[\$r] = \$vTemp
Next
EndFunc```
Edited by czardas

## Create an account

Register a new account