# Help with Keno

## Recommended Posts

Hopfully everyone knows what keno is. Im trying to recreate a version of the game for my own entertainment. Heres my problem. i draw 12 random numbers between 1 and 80 using the random function. 9 times out of 10 2 of the random numbers match. How can i draw 12 ramdom numbers that cannot = numbers already drawn??? hope you understand what i mean

##### Share on other sites

>> /edit: post was already removed by mrbond007 <<

You take twelve numbers from 80 numbers, and needs all those numbers to be different.

The idea behind the big chance of two numbers in the selected 12-element set being equal is explained by the Birthday Paradox (link to wikipedia).

You might make a loop that keeps randomizing the value until it reaches something that has not been chosen in the numbers that were chosen before, but this is by definition not efficient because of the birthday paradox. (Especially if you need to take for instance 70 numbers out of 80 and need them all to be random (/edit: and unique!) - this will take a long time and a whole lotta loops.)

A better way would be to create an array with the numbers you want to choose from in each element, then choosing a random element from the array, and then removing that element from the array. This will need only one Random() operation for each number. For instance:

```#include <Array.au3>
#include <Array.au3>
Dim \$tA[80]      ; <-- tA = total array of all 80 numbers
Dim \$rnArray[12] ; <-- rnArray = Random Numbers array

For \$a = 0 To 79
\$tA[\$a] = \$a + 1
Next

For \$b = 0 To 11
\$randomElementNumber = Random(0, UBound(\$tA) - 1, 1)
\$rnArray[\$b] = \$tA[\$randomElementNumber]
_ArrayDelete(\$tA, \$randomElementNumber)    ; EDIT: Had this line wrong the first time around, sorry
Next

_ArrayDisplay(\$rnArray, "Here are 12 random numbers.")```

Roses are FF0000, violets are 0000FF... All my base are belong to you.

##### Share on other sites

He takes twelve numbers from 80 numbers, and needs all those numbers to be different.

The idea behind the big chance of two numbers in the selected 12-element set being equal is explained by the Birthday Paradox (link to wikipedia).

You might make a loop that keeps randomizing the value until it reaches something that has not been chosen in the numbers that were chosen before, but this is by definition not efficient because of the birthday paradox. (Especially if you need to take for instance 70 numbers out of 80 and need them all to be random (/edit: and unique!) - this will take a long time and a whole lotta loops.)

A better way would be to create an array with the numbers you want to choose from in each element, then choosing a random element from the array, and then removing that element from the array. This will need only one Random() operation for each number. For instance:

```#include <Array.au3>
Dim \$tA[80]      ; <-- tA = total array of all 80 numbers
Dim \$rnArray[12] ; <-- rnArray = Random Numbers array

For \$a = 0 To 79
\$tA[\$a] = \$a + 1
Next

For \$b = 0 To 11
\$randomElementNumber = Random(0, UBound(\$tA) - 1, 1)
\$rnArray[\$b] = \$tA[\$randomElementNumber]
\$totalArray = _ArrayDelete(\$tA, \$randomElementNumber)   ; <-- removes chosen number from array so it cannot be chosen again
Next

_ArrayDisplay(\$rnArray, "Here are 12 random numbers.")```
But i already deleted that post ?? strange

##### Share on other sites

But i already deleted that post ?? strange

Not so strange, I just replied to it while it was still there!

Never mind then. Anyway, I tested my example and it should work. I'll edit my post to remove yours.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

##### Share on other sites

ok i read this but i dont see how it could help me i need my program to sleep for a time 11<x<12

sec but i dont know how to put that in to a script

and it would help if is was sleep ok some thing like that

( after the sleeping it clicks and starts over)

## Create an account

Register a new account

×

• Wiki

• Back

• Git