Skip to content

Commit 304b1dd

Browse files
timotheecourAraq
authored andcommitted
randomize: added doAssert(seed!=0) to avoid invalid (non-random) behavior (#10635)
1 parent e3ba2e2 commit 304b1dd

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/pure/random.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ proc initRand*(seed: int64): Rand =
513513

514514
let now = getTime()
515515
var r2 = initRand(now.toUnix * 1_000_000_000 + now.nanosecond)
516+
doAssert seed != 0 # 0 causes `rand(int)` to always return 0 for example.
516517
result.a0 = ui(seed shr 16)
517518
result.a1 = ui(seed and 0xffff)
518519
discard next(result)

0 commit comments

Comments
 (0)