作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在批处理文件中创建一个不基于系统时钟时间的随机数。
我一直在尝试使用 %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/
我是一名优秀的程序员,十分优秀!