Jump to content

Recommended Posts

Posted (edited)

in this guide i will explain how to generate random numbers

OBS i did NOT make all this my self, sadly i forgot who made this script (well, the creators of autoit i guess xD)

1. if you just want a pop-up box use the code below, u can change it if you want, but only if you know what you do (very easy, but still)

$one = 1
$ten = 3000
 
$RandomPick1 = Random($one,$ten,1)
$RandomPick2 = Random($one,$ten,1)
$RandomPick3 = Random($one,$ten,1)
$RandomPick4 = Random($one,$ten,1)
$RandomPick5 = Random($one,$ten,1)
 
MsgBox(0,"test generator",$RandomPick1 & "-" & $RandomPick2 & "-" & $RandomPick3 & "-" & $RandomPick4 & "-" & $RandomPick5)oÝ÷ Ûhʰj{ZB"ë-§^iìZ^ÁêÞÊ©­ë,éÞ­«^¶µ§(uëkÊØb²Þjëh×6GuiCreate("generator",466,191,339,224)
$button1=GuiCtrlCreateButton("generate",135,63,127,32)
GuiSetState()

While 1
$msg=GuiGetMsg()
If $msg=-3 Then Exit
If $msg=$button1 Then button1()
Wend




Func button1()
$one = 1000
$ten = 9999
 
$RandomPick1 = Random($one,$ten,1)
$RandomPick2 = Random($one,$ten,1)
$RandomPick3 = Random($one,$ten,1)
$RandomPick4 = Random($one,$ten,1)
$RandomPick5 = Random($one,$ten,1)
 
MsgBox(0,"code",$RandomPick1 & "-" & $RandomPick2 & "-" & $RandomPick3 & "-" & $RandomPick4 & "-" & $RandomPick5)
EndFunc

hope it helped!

Edited by join
Posted

How about generate random numbers without duplicates? :P

#include <Array.au3>

;Will generate 5 random numbers, where maximum possible number is 5, and minimum is 1
$aRet = _GenerateRandomNumbers(5, 5, 1) ;This one shows that this function generate really *different* random numbers :)

_ArrayDisplay($aRet)

;Will generate 25 random numbers, where maximum possible number is 150, and minimum is 10
$aRet = _GenerateRandomNumbers(25, 150, 10)

_ArrayDisplay($aRet)

;$iGenerateNums - Total numbers to generate.
;$iMaxEachNum - Largest number to be generated.
;$iMinEachNum - Smallest number to be generated.
;Note: $iGenerateNums can not be grater than ($iMaxEachNum - $iMinEachNum) + 1
Func _GenerateRandomNumbers($iGenerateNums, $iMaxEachNum, $iMinEachNum=0)
    If $iGenerateNums > ($iMaxEachNum - $iMinEachNum) + 1 Then Return SetError(1, 0, 0)
    
    Local $aRandom[$iGenerateNums]
    
    For $i = 0 To $iGenerateNums-1
        While 1
            $aRandom[$i] = Random($iMinEachNum, $iMaxEachNum, 1)
            
            For $j = 0 To $iGenerateNums-1
                If $j = $i Then ContinueLoop
                If $aRandom[$j] = $aRandom[$i] Then ContinueLoop 2
            Next
            
            ExitLoop
        WEnd
    Next
    
    Return $aRandom
EndFunc

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...