ilovesensimillia Posted March 19, 2007 Posted March 19, 2007 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
SadBunny Posted March 19, 2007 Posted March 19, 2007 (edited) >> /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.") Edited March 19, 2007 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you.
mrbond007 Posted March 19, 2007 Posted March 19, 2007 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 Projects : Space Regain - Memory Fusion - PWGT - Chip-ITGames : BrainPain - BrainPain Director's Cut - ProSpeed Games Pack (New)Vista vs XP : the forbidden fight
SadBunny Posted March 19, 2007 Posted March 19, 2007 But i already deleted that post ?? strangeNot 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.
gizmo123 Posted February 11, 2008 Posted February 11, 2008 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)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now