tcl中指定随机数种子

rand()

从区间[0, 1)中均匀采样的随机数。

set a [expr rand()]

srand(arg)

arg必须是整数,用于重置随机数生成器的种子。返回该种子的第一个随机数。每个解释器都有自己的种子。rand()和srand()函数在加密上不安全,不能用于生成一次性密码或会话密钥。对于蒙特卡罗模拟的使用,它们也可能还不够强大。

The arg, which must be an integer, is used to reset the seed for the random number generator. Returns the first random number from that seed. Each interpreter has its own seed.

The rand() and srand() functions are not cryptographically secure, and must not be used to generate one-time passwords or session keys. They are also probably not strong enough for Monte-Carlo simulation usage.

expr srand(123)

set a [expr rand()]

 

参考资料:

https://stackoverflow.com/questions/60181104/is-there-a-way-to-generate-pseudo-random-numbers-with-a-seed-in-tcl-8-5

https://wiki.tcl-lang.org/page/rand

https://wiki.tcl-lang.org/page/srand

 

posted on 2020-08-12 19:31  那抹阳光1994  阅读(1187)  评论(0编辑  收藏  举报

导航