VBScript - How to Generate a Random Number, then an If-Statement to Use this Number to Pick an Option
You need randomize
and rnd
.
int(rnd * n) + 1
evaluates to an integer number between 1 and n.
And you might use select case...
here as well, try this:
dim r
randomize
r = int(rnd*10) + 1
select case r
case 2
'...
case 7
'...
end select
And If you would rand from min to max:
Dim max,min,rand
max=54
min=23
Randomize
rand = Int((max-min+1)*Rnd+min)
WScript.Echo rand