Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
randomize: added doAssert(seed!=0) to avoid invalid (non-random) beha…
…vior (#10635)
  • Loading branch information
timotheecour authored and Araq committed Feb 13, 2019
1 parent e3ba2e2 commit 304b1dd
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/pure/random.nim
Expand Up @@ -513,6 +513,7 @@ proc initRand*(seed: int64): Rand =


let now = getTime() let now = getTime()
var r2 = initRand(now.toUnix * 1_000_000_000 + now.nanosecond) 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.a0 = ui(seed shr 16)
result.a1 = ui(seed and 0xffff) result.a1 = ui(seed and 0xffff)
discard next(result) discard next(result)
Expand Down

0 comments on commit 304b1dd

Please sign in to comment.