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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM