gpt4 book ai didi

random - 同时不同的随机数

转载 作者:行者123 更新时间:2023-12-05 00:15:07 25 4
gpt4 key购买 nike

我有一个看起来像这样的 VBScript

Randomize
Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Random Performance", Int(Rnd*100)+1)
Call oAPI.Return(oBag)

现在,此脚本的多个实例同时运行,因此它们可能都是同时播种的。结果,它们一次都给出相同的随机数。有没有办法让它们同时给出不同的随机值?

最佳答案

我在这方面取得了一些成功,尽管我不知道您是如何运行脚本的,但我使用 start /b 重现了您的问题。

' create a number from the Guid
dim g
g = Mid(CreateObject("Scriptlet.TypeLib").Guid, 2, 36)

dim i, c, s
s = 0
for i = 1 to len(g)
c = Mid(g, i, 1)
if not IsNumeric(c) then
c = Asc(c)
end if
s = CInt(c) + s
next

randomize s

for i = 0 to 5
WScript.Echo(WScript.Arguments(0) & " " & g & " " & CInt(Rnd*100))
next

运行它
start /b cscript test.vbs //nologo 1
start /b cscript test.vbs //nologo 2
start /b cscript test.vbs //nologo 3
start /b cscript test.vbs //nologo 4
start /b cscript test.vbs //nologo 5

样本输出

2D1F39B7-6158-4C77-893B-5C749CF5537F 32 1
2D1F39B7-6158-4C77-893B-5C749CF5537F 13 1
2D1F39B7-6158-4C77-893B-5C749CF5537F 49 1
2D1F39B7-6158-4C77-893B-5C749CF5537F 51 1
2D1F39B7-6158-4C77-893B-5C749CF5537F 84 1
2D1F39B7-6158-4C77-893B-5C749CF5537F 59 3
DC29EDBD-9C63-495B-AFB6-A4A18F65C7F8 35 3
DC29EDBD-9C63-495B-AFB6-A4A18F65C7F8 86 3
DC29EDBD-9C63-495B-AFB6-A4A18F65C7F8 80 3
DC29EDBD-9C63-495B-AFB6-A4A18F65C7F8 3 3
DC29EDBD-9C63-495B-AFB6-A4A18F65C7F8 90 3
DC29EDBD-9C63-495B-AFB6-A4A18F65C7F8 49 4
DC7D2269-436F-4053-B008-F9375BA50F30 34 4
DC7D2269-436F-4053-B008-F9375BA50F30 88 4
DC7D2269-436F-4053-B008-F9375BA50F30 85 4
DC7D2269-436F-4053-B008-F9375BA50F30 60 4
DC7D2269-436F-4053-B008-F9375BA50F30 5 4
DC7D2269-436F-4053-B008-F9375BA50F30 52 2
22F2D6A9-CBF4-48D5-919B-05798FC1BFB1 7 2
22F2D6A9-CBF4-48D5-919B-05798FC1BFB1 89 2
22F2D6A9-CBF4-48D5-919B-05798FC1BFB1 14 2
22F2D6A9-CBF4-48D5-919B-05798FC1BFB1 68 2
22F2D6A9-CBF4-48D5-919B-05798FC1BFB1 89 2
22F2D6A9-CBF4-48D5-919B-05798FC1BFB1 73 5
B13E0D1A-1F93-4387-8CFE-70EEF7FB9B4F 60 5
B13E0D1A-1F93-4387-8CFE-70EEF7FB9B4F 71 5
B13E0D1A-1F93-4387-8CFE-70EEF7FB9B4F 48 5
B13E0D1A-1F93-4387-8CFE-70EEF7FB9B4F 31 5
B13E0D1A-1F93-4387-8CFE-70EEF7FB9B4F 3 5
B13E0D1A-1F93-4387-8CFE-70EEF7FB9B4F 19 5

关于random - 同时不同的随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45319026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com