mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 23:54:19 +00:00
Fix initrand to avoid random number sequences overlapping (#18744)
* Fix initrand to avoid random number sequences overlapping * Minor fix * Fix compile error on js backend * Disable new test for js backend * Minor fix * tempfiles module uses random.initRand() * Remove unused module import from lib/std/tempfiles.nim * Initialize baseState in initRand() * Run tests/stdlib/trandom.nim from tests/test_nimscript.nims * baseState is initialized only with sysrand.urandom and quit if failed * Add comments
This commit is contained in:
@@ -17,7 +17,7 @@ See also:
|
||||
* `mkstemp` (posix), refs https://man7.org/linux/man-pages/man3/mkstemp.3.html
|
||||
]#
|
||||
|
||||
import os, random, std/monotimes
|
||||
import os, random
|
||||
|
||||
|
||||
const
|
||||
@@ -107,11 +107,8 @@ var nimTempPathState {.threadvar.}: NimTempPathState
|
||||
template randomPathName(length: Natural): string =
|
||||
var res = newString(length)
|
||||
if not nimTempPathState.isInit:
|
||||
var time = getMonoTime().ticks
|
||||
when compileOption("threads"):
|
||||
time = time xor int64(getThreadId())
|
||||
nimTempPathState.isInit = true
|
||||
nimTempPathState.state = initRand(time)
|
||||
nimTempPathState.state = initRand()
|
||||
|
||||
for i in 0 ..< length:
|
||||
res[i] = nimTempPathState.state.sample(letters)
|
||||
|
||||
Reference in New Issue
Block a user