summary refs log tree commit diff stats
path: root/tests/stdlib
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-08-02 16:58:29 +0800
committerGitHub <noreply@github.com>2023-08-02 10:58:29 +0200
commitf3a7622514f24740c6b33f0c37ebe6339ad5b70d (patch)
tree45f832511a9db863b162891188ac90c972f40a62 /tests/stdlib
parentda368885da8850c0c87e6b9dcff64393985aff27 (diff)
downloadNim-f3a7622514f24740c6b33f0c37ebe6339ad5b70d.tar.gz
fixes #22360; compare with the half of randMax (#22361)
* fixes #22360; compare with the half of randMax

* add a test
Diffstat (limited to 'tests/stdlib')
-rw-r--r--tests/stdlib/trandom.nim18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/stdlib/trandom.nim b/tests/stdlib/trandom.nim
index 8784b33ee..920d429d4 100644
--- a/tests/stdlib/trandom.nim
+++ b/tests/stdlib/trandom.nim
@@ -282,3 +282,21 @@ block: # bug #17898
       for j in 0..<numRepeat:
         discard rands[i].next
         doAssert rands[i] notin randSet
+
+block: # bug #22360
+  const size = 1000
+  var fc = 0
+  var tc = 0
+
+  for _ in 1..size:
+    let s = rand(bool)
+
+    if s:
+      inc tc
+    else:
+      inc fc
+
+  when defined(js):
+    doAssert (tc, fc) == (483, 517), $(tc, fc)
+  else:
+    doAssert (tc, fc) == (510, 490), $(tc, fc)