Random With a Twist
The random command generates a pseudo-random number between two given parameters. This script adds a 'blackout' zone, a range of numbers in the middle that the script will reject. If the number falls in the 'blackout zone' the script starts again. It will do this as many times as needed to get a 'legal' number.
loop ;*1 { random, ran, 400, 700 ;*2 if (ran > 500 && ran < 600) ;*3 { continue } else ;*4 { break } } msgbox, %ran% ;*5 /* 1 A basic loop. 2 Generates a random number between 400 and 700, storing it in the "ran" variable. 3 If the number in "ran" is anything from 501 to 599 the loop restarts. 4 If "ran" is not between 501 and 599 the loop breaks. 5 A message box displaying the the content of "ran". */ |
I wrote this script because of a request on the AHk help forum. I have no idea what he wanted the script for, but we aim to please.