If statement VBScript-如何生成一个随机数,然后使用If语句使用该数字选择选项
我想知道如何(在VBScript中)在不同的计算机上生成一个不同的随机数,然后使用该随机数和一些If语句,以便激活10个可能选项中的一个,例如If statement VBScript-如何生成一个随机数,然后使用If语句使用该数字选择选项,if-statement,random,vbscript,compilation,If Statement,Random,Vbscript,Compilation,我想知道如何(在VBScript中)在不同的计算机上生成一个不同的随机数,然后使用该随机数和一些If语句,以便激活10个可能选项中的一个,例如 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 t
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)
等等
这样我就有10个不同的选项供脚本随机选择
这可能吗?如果是这样的话,那么有人能够编译一个这样的例子,这样我就可以把我自己的脚本放进去并使用它吗?
谢谢你的回答 您需要
随机化和rnd
int(rnd*n)+1
计算结果为1到n之间的整数。
您也可以在这里使用select case…
,试试这个:
dim r
randomize
r = int(rnd*10) + 1
select case r
case 2
'...
case 7
'...
end select
如果你想从最小值到最大值:
Dim max,min,rand
max=54
min=23
Randomize
rand = Int((max-min+1)*Rnd+min)
WScript.Echo rand
不需要在循环的每次迭代中调用Randomize()
,您很可能会降低过程的随机性。
Dim i
For i=1 to 5
Randomize
a=Rnd
b=a+1
msgbox b
Next