# random numbers (working good)

## Recommended Posts

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
##### Share on other sites

How about generate random numbers without duplicates?

```#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```

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

My Work...

Spoiler

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating )

* === My topics === *

==================================================

==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

##### Share on other sites

it´s not repeting...

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...