Random numbers?
Random numbers?
How would I go about generating a random number between 2 and 7?
Re: Random numbers?
Random, OutputVar, 2, 7
Re: Random numbers?
Yeah, thanx guys. I was just going to post "Never mind. I figured it out." Duh!
Re: Random numbers?
There is also https://biga-ahk.github.io/biga.ahk/#/?id=random which is nice so you don't need a placeholder outputvar
- flyingDman
- Posts: 2791
- Joined: 29 Sep 2013, 19:01
Re: Random numbers?
I do and I did. I just asked here before looking it up in the help files.
Re: Random numbers?
Please do it the other way around in the future. And if you can’t find the answer in the help files, try searching the forum or performing a general internet search. Creating a new forum thread should happen after all else fails.
-
- Posts: 481
- Joined: 03 Dec 2018, 20:02
Re: Random numbers?
See? This is why I asked here first. Because this kind of tidbit is not found in the help files.Chunjee wrote: ↑01 Feb 2023, 19:56There is also https://biga-ahk.github.io/biga.ahk/#/?id=random which is nice so you don't need a placeholder outputvar
Re: Random numbers?
Not to disparage biga, because there are certainly some worthwhile methods in it, but do you really want to add 3100 lines of code to your script to save a placeholder variable? The portion of biga's code that is the random method actually uses its own placeholder variable and consumes 18 lines of code. You can write your own function in 4.
Russ
Code: Select all
MsgBox, % Rand(2,7)
Return
Rand(min,max){
Random, RandNum, min, max
Return RandNum
}
Re: Random numbers?
In web development; library size is worth considering, because the browser will have to download the file(s) before using them. This is not true of ahk apps, so line size has little or no meaning, doesn't slow down the app, etc.
Although you can write your own function, this doesn't scale well if you have to remember to bring 10, 20, or more functions everywhere when needed or have more than one computer the script needs to run on.
Russ
Re: Random numbers?
That's not a good reason for not doing the simplest of searches of the help file for the Random command before posting a thread about it. The forum members are not your personal Ctrl+F, so please don't start new threads of this type in the future.