在该批次随机数发生器 [英] Random generator in the batch

查看:132
本文介绍了在该批次随机数发生器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bat文件

@echo %RANDOM%

和使用命令行执行它

start randomcheck.bat & start randomcheck.bat

两个控制台打开,都包含相同的号码,4645.这将失败,随机的提供不同的临时文件夹(我需要随机的文件夹,只有当simulataneously使用它们)。你怎么有正常的随机数发生器在批处理?

Two consoles are opened and both contain the same number, 4645. This fails the purpose of random to provide different temp folders (I need random folders only when use them simulataneously). How you have normal random generator in batch?

更新
http://stackoverflow.com/a/19697361/1083704 量化了全球种子更新周期。 Windows外壳程序的全球种子每秒更新一次。实际上,我必须补充的安全余量多了一个第二,prevent的比赛,并希望这是足够的措施。这真的很烂。这意味着,发起对我iCore7 8进程将需要16秒。我仍然不知道这成功,因为没有正式规定,它仍然是可能的,尽管8进程相对时移最初启动,可能会发生两个过程完成的同时,我必须照顾他们不能同时再重新启动。这完全是胡说八道,我的问题是可以在此批处理中被治愈,而不是诉诸C ++或VBScript?

Update http://stackoverflow.com/a/19697361/1083704 has quantified the global seed update period. The windows shell global seed is updated every second. Practically, I must add one more second for safety margin, to prevent the races and hope that this is sufficient measure. This really sucks. It means that launching 8 processes for my iCore7 will take 16 seconds. And I am still not sure that this succeeds since nothing is officially specified and it is still possible that despite 8 processes are started initially with relative time shift, it may happen that two processes finish at the same time and I must take care that they are not restarted simultaneously again. This is complete bullshit and my question was can this be cured in the batch, without resorting to C++ or VBScript?

推荐答案

$ RANDOM 在bash没有这个缺陷。

$RANDOM in bash does not have this flaw.

@echo win=%RANDOM%

@for /f %%i in ('bash -c "echo $RANDOM"') do @set VAR=%%i

@echo cygwin=%VAR%

当我运行启动randomcheck.bat和放大器输出相同的Windows数字,但不同的cygwin的人;启动randomcheck.bat 。使用的cygwin是比单个命令写入一个单独的VBScript更好。可能是你可以教我如何更换的bash -c回声$ RANDOM与Windows脚本宿主的选择,这将消除安装cygwin的需要。

prints the same windows numbers but distinct cygwin ones when I run start randomcheck.bat & start randomcheck.bat. Using cygwin is better than writing a separate VBScript for a single command. Might be you can teach me how to replace the bash -c "echo $RANDOM" with the windows scripting host alternative, which would eliminate the need for installing the cygwin.

这篇关于在该批次随机数发生器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆