Random and functions ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chango
Posts: 30
Joined: 27 May 2017, 12:10

Random and functions ?

26 Mar 2018, 10:39

I didn't know what to put in the title sorry..
What I have is a random number ( used for a random time of pause) generated using Random.. which works great .

Random, RandPause30to60, 30000, 60000
Sleep, %RandPause30to60%

I'm trying to pair down the code as I find myself having to Run the Random generator each time I use a pause, otherwise the variable is not populated with a newly randomized number.
Is there a way of making a function or something that when used triggers the Random and passes that to a varible anywhere in the code, or do I just have to repeat the Random code every-time I need a new number ?
Although its not a huge problem as I expect if I created a function I would still have to paste the function code in, was just curious if anyone had a niffty way of .. like I said "shrinking" the code for this type of problem. :crazy:

Thanks

:)
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Random and functions ?

26 Mar 2018, 12:20

Code: Select all

Sleep % Rand(30,60)
SoundBeep
Sleep % Rand(15,30)
SoundBeep
Sleep % Rand(0.5,2)
SoundBeep
MsgBox % Rand(200,300)
F12::MouseMove, Rand(0,A_ScreenWidth), Rand(0,A_ScreenHeight)

Rand(min,max) {
    Random, res, min, max
    Return res * 1000
    }
Not tested.
chango
Posts: 30
Joined: 27 May 2017, 12:10

Re: Random and functions ?

26 Mar 2018, 14:37

BoBo wrote:

Code: Select all

Sleep % Rand(30,60)
SoundBeep
Sleep % Rand(15,30)
SoundBeep
Sleep % Rand(0.5,2)
SoundBeep
MsgBox % Rand(200,300)
F12::MouseMove, Rand(0,A_ScreenWidth), Rand(0,A_ScreenHeight)

Rand(min,max) {
    Random, res, min, max
    Return res * 1000
    }
Not tested.
Thanks I'll try this out :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], bobstoner289, Google [Bot], peter_ahk and 331 guests