# Any Suggestions on Random numbers?

## Recommended Posts

• Moderators

Hey all, any suggestions on how to get my random numbers in multiples of 5?

`Send(Random(.25, 2, 0) & "{ENTER}")`

Current code gives numbers like .987888393 and 1.445959382, would rather see 1.00 and 1.45. Any ideas?

Thanks

Ron

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

they aren't going to be random numbers lol. the generator creates pseudo-random numbers as there is no distinctly visible pattern. but if you're numbers are only in multiples of 5 then that is order, and order is the antithesis to being random (or chaos, or what-have-you)

but um, you're gigahurtz pounding processor can spit these out pretty quickly. use StringFormat to limit it to two decimal places (you'll use "%.2f" offhand I believe) and then use a while loop to detect if it's divisible by five or not.

PS you could also try rounding...

Edited by Alterego
##### Share on other sites

Three methods to choose from; beware of logical errors in my impelemtations and possible bias of random numbers:

You could probably also use a method where you generate a random multiple of five between 25 and 200 and then divide the result by 100.

```HotKeySet("{Esc}", "Quit")
Func Quit()
Exit
EndFunc

While 1
sleep(500)
ToolTip("Number:  " & _SpecialRandomZero(), 0,0)
Wend

;All you want is to ensure the last digit is a zero or a five
;Actually if the last digit is a zero, it's omitted and the length of the
;Leading zero appears to be included, so test StringLen

;Alterego's method:
Func _SpecialRandomZero()
Do
Local \$rnd = Round(Random(0.25, 2.00), 2)
Until StringLen(\$rnd) < 4 or StringRight(\$rnd,1) = "5"
Return \$rnd
EndFunc

;String-of-digits method:
Func _SpecialRandomOne()
Local \$ones = Random(0, 2, 1);either 0 or 1 or 2
Local \$body = Random(0, 9, 1);we only need one middle digit
Local \$lastDigit = 5 * Random(0, 1, 1);either zero or five
Return Number(\$ones & "." & \$body & \$lastDigit)
EndFunc

;Put all possible valid numbers in an array
;  and randomly select an array element
Func _SpecialRandomTwo()
Local \$array = ""
For \$i = 0.25 To 2.00 Step 0.05
\$array = \$array & \$i & "|"
Next
\$array = StringSplit(\$array,"|")
; ignore element zero it's reserved by StringSplit
; and ignore last element due to the trailing pipe char
Return \$array[ Random(1,\$array[0],1) ]
EndFunc```
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...