Sign in to follow this  
Followers 0
Minikori

20 different random integers?

17 posts in this topic

Hey, I'm making a Keno game, but I don't know how to get 20 different numbers between 1 and 80. Does someone know a math equation I could do? Any other way would be extremely helpful. Thanks in advance!


For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites



look at random in the help files


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

look at random in the help files

If you read my other posts, I don't like people who don't look at the helpfile. I looked, and I know of the Random function. What I need, is 20 DIFFERENT numbers, and Random() can't return 20 DIFFERENT numbers everytime.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

Hey, I'm making a Keno game, but I don't know how to get 20 different numbers between 1 and 80. Does someone know a math equation I could do? Any other way would be extremely helpful. Thanks in advance!

Hi there m8

Something like this?

$output = ""
for $x = 0 to 20
    $number = Random(1, 80, 1)
    $output = $output & $number & @CRLF
Next
MsgBox(0, "result", $output)

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Ah.. I get ya... just a sec.


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

sorry it took me so long.. I got interrupted.

#include <Array.au3>
Dim $array[2]
$array[1] = Random(1, 80, 1)

While 1
    $clear = 1
    $tmp = Random(1, 80, 1)
    For $i = 1 To UBound($array) - 1
        If $array[$i] = $tmp Then $clear = 0
    Next
    If $clear Then
        ReDim $array[UBound($array) + 1]
        $array[UBound($array) - 1] = $tmp
    EndIf
    If UBound($array) - 1 = 20 Then ExitLoop
WEnd
_ArrayDisplay($array, "20 different random numbers")

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I wrote a Keno game and I think I just used something like

Func _GenNums($iMax = 20)
$count = 0
$sOut = ""
While $Count <> $iMax
   $sNum = Random(1, 80, 1) & "|"
   If NOT StringInStr($sOut, $sNum) Then
      $sOut &= $sNum
      $count += 1
   EndIf
Wend
   Return StringSplit(StringTrimRight($sOut, 1), "|")
EndFunc

The reason for using the $iMax parameter was because I also did a few other lottery ganes that need random numbers, for example 6/49 (Pick 6).

EDIT: Jus remembered that I also used thisfunction to generate betting slip numbers if someone clicked the "Quick Pick" button.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I did something simular too, some time ago:

#515701


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

GEOSoft's example gave me a chance the play with the functions from the Array.au3 file.

#include <Array.au3>
local $aArray = _GenNums(20)
_ArrayDelete($aArray,0)
_ArraySort($aArray,0,0)
_ArrayDisplay($aArray)
Func _GenNums($iMax = 20)
$count = 0
$sOut = ""
While $Count <> $iMax
   $sNum = Random(1, 80, 1) & "|"
   If NOT StringInStr($sOut, $sNum) Then
      $sOut &= $sNum
      $count += 1
   EndIf
Wend
   Return StringSplit(StringTrimRight($sOut, 1), "|")
EndFunc

Edit: The ArraySort() does not seem to consistently sort correctly, nor with beta version 3.2.13.11.

Edited by Malkey

Share this post


Link to post
Share on other sites

GEOSoft's example gave me a chance the play with the functions from the Array.au3 file.

#include <Array.au3>
local $aArray = _GenNums(20)
_ArrayDelete($aArray,0)
_ArraySort($aArray,0,0)
_ArrayDisplay($aArray)
Func _GenNums($iMax = 20)
$count = 0
$sOut = ""
While $Count <> $iMax
   $sNum = Random(1, 80, 1) & "|"
   If NOT StringInStr($sOut, $sNum) Then
      $sOut &= $sNum
      $count += 1
   EndIf
Wend
   Return StringSplit(StringTrimRight($sOut, 1), "|")
EndFunc

Edit: The ArraySort() does not seem to consistently sort correctly, nor with beta version 3.2.13.11.

_ArraySort has a bad track record when doing numbers.

_ArraySortClib() by Siao is much better at that job. It's the last function on this page.

Now, here's the rub, Keno boards generally do not display the numbers in a sorted order. They are displayed in the random drawing sequence. The only thing to be gained by sorting the array in this case is the experience.

I don't know if the OP is going to be adding betting slips to this version or not but that's where the math gets a bit more difficult. Our provincial Keno odds are posted for the public to see so I had to duplicate those odds exactly. There is also a Bonus that comes up every so often. 0x, 2x, 3x, 5x and 10x. Those values also have to be random and I had to also duplicate the odds of each of those coming up. Then there is the matter of tracking the prize pool and tracking the amounts paid in and the amounts paid out. My version also draws on exactly the same schedule as the Provincial game and the board appearance is as close to an actual display board as I could get.. To get a full duplicate game of the original requires quite a bit of math if you are going with the betting slips.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Another (more elegant) way, without using includes...

$Numbers = ""
For $i = 1 to 20
    Do
        $rnd = Random(1,80,1)
    Until StringRegExp($Numbers,"," & $rnd & ",") = 0
    $Numbers &= $rnd & ","
Next
MsgBox(0,"",$Numbers)

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites

Another (more elegant) way, without using includes...

...

Nice, I noted the includes also because of all the "overhead", however there are no includes with Geo's either!

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Nice, I noted the includes also because of all the "overhead", however there are no includes with Geo's either!

8)

I hate using the standard includes unless I have to. I much prefer to create my own using only the functions that I need for a particular script.

For anyone that is interested, here is a couple of screenshots of my Keno board. The first is with the betting slip enabled and the second is the board only. @Val, If you look closly at the title bar you may recognize some code that I posted in the wrappers thread a long time ago.

BTW With the board only image, I managed to capture it just as the next draw time was updating so that time doesn't show. It's the same as in the other one normally.

Posted Image

Posted Image


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

This could be useful, generate a random array of 80 characters.

Then just pick 1 through 20 of the array for your 20 random numbers, or 2 through 21 etc...

Func _ArrayRandomShuffle($av_array, $i_lbound = 0)
    Local $i_ubound = UBound($av_array) - 1
    Local $icc, $s_temp, $i_random
    
    For $icc = $i_lbound To $i_ubound
        $s_temp = $av_array[$icc]
        $i_random = Random($i_lbound, $i_ubound, 1)
        $av_array[$icc] = $av_array[$i_random]
        $av_array[$i_random] = $s_temp
    Next
    
    Return $av_array
EndFunc

You have to pass it an array of 80 numbers.. you could do something like:

$a_array = _Create_Number_Array(1, 80, 81)
Func _Create_Number_Array($i_base, $i_max, $i_ubound)
    Local $a_ret[$i_ubound]
    For $i = $i_base To $i_max
        $a_ret[$i] = $i
    Next
    Return $a_ret
EndFunc

So all together would look like:

#include <array.au3>; Only so you can see the display of the array

$a_array = _Create_Number_Array(1, 80, 81)
$a_random = _ArrayRandomShuffle($a_array, 1)
_ArrayDisplay($a_random)

Func _ArrayRandomShuffle($av_array, $i_lbound = 0)
    Local $i_ubound = UBound($av_array) - 1
    Local $icc, $s_temp, $i_random
    
    For $icc = $i_lbound To $i_ubound
        $s_temp = $av_array[$icc]
        $i_random = Random($i_lbound, $i_ubound, 1)
        $av_array[$icc] = $av_array[$i_random]
        $av_array[$i_random] = $s_temp
    Next
    
    Return $av_array
EndFunc

Func _Create_Number_Array($i_base, $i_max, $i_ubound)
    Local $a_ret[$i_ubound]
    For $i = $i_base To $i_max
        $a_ret[$i] = $i
    Next
    Return $a_ret
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

sorry it took me so long.. I got interrupted.

#include <Array.au3>
Dim $array[2]
$array[1] = Random(1, 80, 1)

While 1
    $clear = 1
    $tmp = Random(1, 80, 1)
    For $i = 1 To UBound($array) - 1
        If $array[$i] = $tmp Then $clear = 0
    Next
    If $clear Then
        ReDim $array[UBound($array) + 1]
        $array[UBound($array) - 1] = $tmp
    EndIf
    If UBound($array) - 1 = 20 Then ExitLoop
WEnd
_ArrayDisplay($array, "20 different random numbers")oÝ÷ Ûú®¢×z··öËayÊxZ½çè®Ø^¦V²x)j»ZºÚ"µÍØÙH ÌÍÛÙÈH ÌÍÔ^P]BBIÌÍØ^VÌWHH[ÛJKJBBBQÜ   ÌÍÞHHÈBBBIÌÍØÛXHBBBBIÌÍÝH[ÛJKJBBBBQÜ   ÌÍÚHHHÈPÝ[
    ÌÍØ^JHHBBBBBRY   ÌÍØ^VÉÌÍÚWHH ÌÍÝ[ ÌÍØÛXHBBBS^BBBRY    ÌÍØÛX[BBBBTQ[H  ÌÍØ^VÕPÝ[
    ÌÍØ^JH
ÈWBBBBBIÌÍØ^VÕPÝ[
    ÌÍØ^JHHWHH   ÌÍÝBBBQ[YBBS^BBQÜ   ÌÍÞHHÈBBBIÌÍÞHH  ÌÍØ^VÉÌÍÞBBBBQÕRPÝÙ]ÛÛÜ    ÌÍÓ[VÉÌÍÞWK
BBBS^

The array $Num is the labels for the numbers. Almost every time I click the play button ($PlayBut), it exits and gives me the error:

CODE
Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$y = $array[$x]

$y = ^ ERROR

Anyone know why?

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Because you have the arrays wrong. Using the function code I gave you it is something like this.

Case $msg = $PlayBut
   $aNums = _GenNums()
   For $x = 1 To Ubound($aNums) -1
      GUICtrlSetColor(Eval("Num" & $aNums[$x]), 0xFF0000)
      Sleep(2000);; Delay time for better display, without it the numbers will appear all at the same time.
   Next

Func _GenNums($iMax = 20)
$count = 0
$sOut = ""
While $Count <> $iMax
   $sNum = Random(1, 80, 1) & "|"
   If NOT StringInStr($sOut, $sNum) Then
      $sOut &= $sNum
      $count += 1
   EndIf
Wend
   Return StringSplit(StringTrimRight($sOut, 1), "|")
EndFunc

BTW this is without seeing the rest of the code so consider it a guess at what you are doing.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Based on what you seem to want, I whipped this up from the code I gave you plus some of the GUI code that I used.

I changed the label names to reflect what you are using currently and added in a play button. Mine is triggered from a menu item.

Opt ("GUICoordMode", 2)
$Gh = 380
$Gw = 455
Global $iDispTime = 1200;; Adjust this for the display delay time.
$Frm_Main = GUICreate("My Keno Board",$Gw,$Gh + 20)
GUISetBkColor(0x000000)
GUICtrlSetDefColor(0x500000)
$iXcoord = 10
$iYcoord = 5
$N_Start = GUICtrlCreateDummy()
For $I = 1 To 80
  If $I > 1 Then
    If StringRight($i, 1) = 1 Then
      $iXCoord = -436
      $iYCoord = 2
    Else
      $iXCoord = 4
      $iYCoord = -1
    EndIf
  EndIf
  Assign("Num" & $i, GUICtrlCreateLabel($i,$iXcoord,$iYcoord,40, 40, 1))
  GUICtrlSetFont(-1,24,800)
Next
GUISetCoord(($Gw/2) -40, $Gh -35)
$Btn_Play = GUICtrlCreateButton("&Play", -1, -1, 80, 30)
GUICtrlSetColor($Btn_Play, 0x000000)
GUICtrlSetFont($Btn_Play, 11)
GUISetState()
While 1
   $Msg = GUIGetMsg()
   Switch $Msg
      Case -3
         Exit
      Case $Btn_Play
         _Reset()
         $aNums = _GenNums()
         Sleep(800);; Insert a short delay before the numbers start to display
         For $x = 1 To Ubound($aNums) -1
            GUICtrlSetColor(Eval("Num" & $aNums[$x]), 0xFF0000)
            Sleep($iDispTime)
         Next
      Case Else
   EndSwitch
Wend

Func _GenNums($iMax = 20)
   $count = 0
   $sOut = ""
   While $Count <> $iMax
      $sNum = Random(1, 80, 1) & "|"
      If NOT StringInStr($sOut, $sNum) Then
         $sOut &= $sNum
         $count += 1
      EndIf
   Wend
   Return StringSplit(StringTrimRight($sOut, 1), "|")
EndFunc

Func _Reset()
  ;; You can remove this loop.  It just gives a fancy flash before reseting
  ;; The effect is more noticable after the first run
   For $i = 1 To 80
      GUICtrlSetColor(Eval("Num" & $i), 0xFF0000)
   Next
   Sleep(400); If you remove the loop above you should also remove this
   For $i = 1 To 80
      GUICtrlSetColor(Eval("Num" & $i), 0x500000)
   Next
EndFunc

Play with it as much as you want.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0