VBScript - How to create a random number, then If-Statement to use this number to select an option

I would like to know how (in VBScript) to generate a random number that will not be the same on another computer, and then use that number and possibly some If-Statement so that one of the 10 possible options can be activated, for example.

If (A random number between 1 - 10, eg. 2) then (Continue on part of script then wscript.quit) Else if (A different number, eg. 7) then (continue on to different part of script then wscript.quit) 

and etc.

So, I would have 10 different options for a script for random selection.

Is it possible? If so, can someone compile an example of this so that I can put my own script inside and use it? Thanks for answers!

+8
source share
4 answers

You need randomize and rnd .
int(rnd * n) + 1 evaluates to an integer from 1 to n.
And here you can use select case... , try the following:

 dim r randomize r = int(rnd*10) + 1 select case r case 2 '... case 7 '... end select 
+10
source

And if you will be rand from min to max:

 Dim max,min,rand max=54 min=23 Randomize rand = Int((max-min+1)*Rnd+min) WScript.Echo rand 
+5
source

You can get a random number from 1 to 32

 Randomize N=32 ' Gen number Too n. MsgBox (Int(Rnd*N)) 
0
source
 Dim i For i=1 to 5 Randomize a=Rnd b=a+1 msgbox b Next 
-2
source

Source: https://habr.com/ru/post/951954/


All Articles