gpt4 book ai didi

batch-file - 如何在不基于系统时钟的CMD中生成随机数

转载 作者:行者123 更新时间:2023-12-03 11:18:26 26 4
gpt4 key购买 nike

我想在批处理文件中创建一个不基于系统时钟时间的随机数。

我一直在尝试使用 %RANDOM% 但它不能很好地满足我的需求。

原因是我想将我在多个线程中收到的文件名写入文件,并且当我使用系统时间 %RANDOM% 方法时,我在文件之间发生冲突,因为系统时间基于秒而不是毫秒。

所以我需要一种方法来根据系统时间以外的其他因素生成随机数...

最佳答案

如果问题是您正在运行多个线程,您能否为每个批处理文件为每个不同的线程提供一个“唯一 ID”变量(例如 id)并将其附加到 的末尾code>%random% 为每个生成不同的数字。例如:

::: Call your batch files with a unique parameter for each thread (e.g. "prog.bat 1")
set id=%%1
::: Alternatively if you're starting each thread at a different time:
:: set id=%random%

:: Later in the batch file when you're writing a file
echo %random%%id%
:: ^ a unique random number for each thread

如果多线程是你唯一的问题,这应该可行。

关于batch-file - 如何在不基于系统时钟的CMD中生成随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38869783/

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