随机数不是随机的?

时间:2014-01-10 17:35:14

标签: random vbscript

下面发布的脚本不会给出不同的x值;它始终设置为100.当我打开文档时,它总是会给我100,100,100等字符串。

Dim intHighNumber,intLowNumber,intNumbers,intNumber, x, strX

intHighNumber = 10000

intLowNumber = 1

intNumbers = InputBox("Amount of players?")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Users\thijsel\Documents\Risk\Risk.txt")

For i = 1 To intNumbers

    Randomize

    intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)


If intNumber=0000 Or 1111 Or 2222 Or 3333 Or 4444 Or 5555 Or 6666 Or 7777 Or 8888 Or 9999 Or 1234 Or 2345 Or 3456 Or 4567 Or 5678 Or 6789 Then
x = 100
ElseIf intNumber=123 Or 234 Or 345 Or 456 Or 567 Or 678 Or 789 Or 1123 Or 1345 Or 1456 Or 1567 Or 1678 Or 1789 Or 2123 Or 2234 Or 2456 Or 2567 Or 2678 Or 2789 Or 3123 Or 3234 Or 3345 Or 3567 Or 3678 Or 3789 Or 4123 Or 4234 Or 4345 Or 4456 Or 4678 Or 4789 Or 5123 Or 5234 Or 5345 Or 5456 Or 5567 Or 5789 Or 6123 Or 6234 Or 6345 Or 6456 Or 6567 Or 6678 Or 7123 Or 7234 Or 7345 Or 7456 Or 7567 Or 7678 Or 7789 Or 8123 Or 8234 Or 8345 Or 8456 Or 8567 Or 8678 Or 8789 Or 9123 Or 9234 Or 9345 Or 9456 Or 9567 Or 9678 Or 9789 Then
x = 50
Else 
x = 3
End If
strX = strX & ", " & x
Next
objFile.Write(strX)
objFile.Close

1 个答案:

答案 0 :(得分:1)

表达式intNumber=0000(应该写成intNumber=0)通常可能是False。表达式False Or 1111将始终为True,因为数字<> 0评估为True。因此,无论intNumber的值如何,第一个条件将始终满足。