Random Number String Generator

Post your working scripts, libraries and tools
ThunderSnow

Random Number String Generator

12 Aug 2018, 22:25

I have created a script that generates an array of random numbers and builds a string that contains the random numbers separated by commas.

I was building this to see if I could autopopulate an excel spreadsheet with some data that I could then try to manipulate but I got pretty hung up on this part so I'm glad I finally got it. :D

Maybe someone else would find this useful, I'm new to AHK so apologies if I did stuff in weird ways. I looked around but I didn't see anybody did exactly something like this. It seems weird to me you have to create a second variable for the second loop and you can't name it the same as the first variable. How do you do something like n = n + 1 then? I'm more used to how it is in Java, this language is a whole 'nother ballgame for me!

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
TheDewd
Posts: 976
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Random Number String Generator

Yesterday, 16:06

I think this is what you are trying to do... Wanted to give you another example.

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

#SingleInstance, Force ; Allow only one running instance of script

N := 10 ; How many random numbers to generate
RandStr := "" ; Initialize variable to store combined random number string

Loop, % N { ; Loop [N] times
Random, Rand, 1, 100 ; Return number from given range
RandStr .= Rand (A_Index = N ? "" : ", ") ; Append value to existing variable contents (in this case, it's initially an empty string). Used ternary to specify whether or not to add a comma... If A_Index = 10 (last number) don't add comma, else add the comma.
}

MsgBox, % RandStr ; Display string in MessageBox


Other examples related to your inquiries:

Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus


Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 26 guests