summary refs log tree commit diff stats
path: root/lib/std/tempfiles.nim
diff options
context:
space:
mode:
authorTomohiro <gpuppur@gmail.com>2021-09-02 21:12:14 +0900
committerGitHub <noreply@github.com>2021-09-02 14:12:14 +0200
commit7c8ea490a2be36d171d362c43212195ea8ce489f (patch)
tree0c3a54a233e999ddf008ddbe99c4ca6311cded40 /lib/std/tempfiles.nim
parente0ef859130f429df1891e31a85955daa753346b4 (diff)
downloadNim-7c8ea490a2be36d171d362c43212195ea8ce489f.tar.gz
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
Diffstat (limited to 'lib/std/tempfiles.nim')
-rw-r--r--lib/std/tempfiles.nim7
1 files changed, 2 insertions, 5 deletions
diff --git a/lib/std/tempfiles.nim b/lib/std/tempfiles.nim
index f1cfd5885..26786d463 100644
--- a/lib/std/tempfiles.nim
+++ b/lib/std/tempfiles.nim
@@ -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)