summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2019-01-30 17:31:06 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-01-30 17:31:06 +0100
commit9ac0cbdd51e838bbe4b040ac2df67fa050e6ac07 (patch)
treefd023210757c2e94ee42afad70feabf2ec11ce0e
parent7118e1ca01e1892208836411b3e4801f06b028c3 (diff)
downloadNim-9ac0cbdd51e838bbe4b040ac2df67fa050e6ac07.tar.gz
fixes #2796 (#10500) [backport]
-rw-r--r--lib/pure/oids.nim20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim
index d6369b5f9..3aee3941d 100644
--- a/lib/pure/oids.nim
+++ b/lib/pure/oids.nim
@@ -60,23 +60,21 @@ proc `$`*(oid: Oid): string =
   result = newString(24)
   oidToString(oid, result)
 
+proc rand(): cint {.importc: "rand", header: "<stdlib.h>", nodecl.}
+proc srand(seed: cint) {.importc: "srand", header: "<stdlib.h>", nodecl.}
+
+var t = getTime().toUnix.int32
+srand(t)
+
 var
-  incr: int
-  fuzz: int32
+  incr: int = rand()
+  fuzz: int32 = rand()
 
 proc genOid*(): Oid =
   ## generates a new OID.
-  proc rand(): cint {.importc: "rand", header: "<stdlib.h>", nodecl.}
-  proc srand(seed: cint) {.importc: "srand", header: "<stdlib.h>", nodecl.}
-
-  var t = getTime().toUnix.int32
-
+  t = getTime().toUnix.int32
   var i = int32(atomicInc(incr))
 
-  if fuzz == 0:
-    # racy, but fine semantically:
-    srand(t)
-    fuzz = rand()
   bigEndian32(addr result.time, addr(t))
   result.fuzz = fuzz
   bigEndian32(addr result.count, addr(i))