mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 19:52:36 +00:00
randomize: added doAssert(seed!=0) to avoid invalid (non-random) behavior (#10635)
This commit is contained in:
committed by
Andreas Rumpf
parent
e3ba2e24cf
commit
304b1dd34b
@@ -513,6 +513,7 @@ proc initRand*(seed: int64): Rand =
|
||||
|
||||
let now = getTime()
|
||||
var r2 = initRand(now.toUnix * 1_000_000_000 + now.nanosecond)
|
||||
doAssert seed != 0 # 0 causes `rand(int)` to always return 0 for example.
|
||||
result.a0 = ui(seed shr 16)
|
||||
result.a1 = ui(seed and 0xffff)
|
||||
discard next(result)
|
||||
|
||||
Reference in New Issue
Block a user