Sign in to follow this  
Followers 0

Any Suggestions on Random numbers?

3 posts in this topic

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?



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

#2 ·  Posted (edited)

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 this post

Link to post
Share on other sites

#3 ·  Posted (edited)

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()

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

;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()
        Local $rnd = Round(Random(0.25, 2.00), 2)
    Until StringLen($rnd) < 4 or StringRight($rnd,1) = "5"
    Return $rnd

;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)

;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 & "|"
    $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) ]
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!

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