Random numbers?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Random numbers?

Post by PepeLapiu » 01 Feb 2023, 17:05

How would I go about generating a random number between 2 and 7?



PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Random numbers?

Post by PepeLapiu » 01 Feb 2023, 19:06

Yeah, thanx guys. I was just going to post "Never mind. I figured it out." Duh!


User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Random numbers?

Post by flyingDman » 01 Feb 2023, 20:05

This boggles my mind. Don't you have access to the help file?
14.3 & 1.3.7

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Random numbers?

Post by PepeLapiu » 01 Feb 2023, 21:09

flyingDman wrote:
01 Feb 2023, 20:05
This boggles my mind. Don't you have access to the help file?
I do and I did. I just asked here before looking it up in the help files.

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Random numbers?

Post by boiler » 01 Feb 2023, 22:50

PepeLapiu wrote: I just asked here before looking it up in the help files.
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.

william_ahk
Posts: 481
Joined: 03 Dec 2018, 20:02

Re: Random numbers?

Post by william_ahk » 01 Feb 2023, 23:11

PepeLapiu wrote:
01 Feb 2023, 21:09
I do and I did. I just asked here before looking it up in the help files.
In case you don't know, you can search in the help file.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Random numbers?

Post by PepeLapiu » 08 Feb 2023, 15:09

Chunjee wrote:
01 Feb 2023, 19:56
There is also https://biga-ahk.github.io/biga.ahk/#/?id=random which is nice so you don't need a placeholder outputvar
See? This is why I asked here first. Because this kind of tidbit is not found in the help files.

RussF
Posts: 1237
Joined: 05 Aug 2021, 06:36

Re: Random numbers?

Post by RussF » 08 Feb 2023, 15:37

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.

Code: Select all

MsgBox, % Rand(2,7)
Return

Rand(min,max){
    Random, RandNum, min, max
    Return RandNum
}
Russ

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: Random numbers?

Post by Chunjee » 08 Feb 2023, 16:18

RussF wrote:
08 Feb 2023, 15:37
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.
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

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Random numbers?

Post by boiler » 08 Feb 2023, 17:06

PepeLapiu wrote: See? This is why I asked here first. Because this kind of tidbit is not found in the help files.
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.

Post Reply

Return to “Ask for Help (v1)”