mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
* fixes #22360; compare with the half of randMax
* add a test
(cherry picked from commit f3a7622514)
This commit is contained in:
@@ -381,10 +381,7 @@ proc rand*[T: Ordinal](r: var Rand; t: typedesc[T]): T {.since: (1, 7, 1).} =
|
||||
when T is range or T is enum:
|
||||
result = rand(r, low(T)..high(T))
|
||||
elif T is bool:
|
||||
whenJsNoBigInt64:
|
||||
result = (r.next or 0) < 0
|
||||
do:
|
||||
result = cast[int64](r.next) < 0
|
||||
result = r.next < randMax div 2
|
||||
else:
|
||||
whenJsNoBigInt64:
|
||||
result = cast[T](r.next shr (sizeof(uint)*8 - sizeof(T)*8))
|
||||
|
||||
Reference in New Issue
Block a user