make random.nim work for the JS target again
This commit is contained in:
parent
13649778c1
commit
6acfbb9e1d
1 changed files with 4 additions and 2 deletions
|
|
@ -19,10 +19,12 @@ include "system/inclrtl"
|
||||||
# XXX Expose RandomGenState
|
# XXX Expose RandomGenState
|
||||||
when defined(JS):
|
when defined(JS):
|
||||||
type ui = uint32
|
type ui = uint32
|
||||||
|
|
||||||
|
const randMax = 4_294_967_295u32
|
||||||
else:
|
else:
|
||||||
type ui = uint64
|
type ui = uint64
|
||||||
|
|
||||||
const randMax = 18_446_744_073_709_551_615u64
|
const randMax = 18_446_744_073_709_551_615u64
|
||||||
|
|
||||||
type
|
type
|
||||||
RandomGenState = object
|
RandomGenState = object
|
||||||
|
|
@ -76,7 +78,7 @@ proc random*(max: int): int {.benign.} =
|
||||||
## number, i.e. a tickcount.
|
## number, i.e. a tickcount.
|
||||||
while true:
|
while true:
|
||||||
let x = next(state)
|
let x = next(state)
|
||||||
if x < randMax - (randMax mod uint64(max)):
|
if x < randMax - (randMax mod ui(max)):
|
||||||
return int(x mod uint64(max))
|
return int(x mod uint64(max))
|
||||||
|
|
||||||
proc random*(max: float): float {.benign.} =
|
proc random*(max: float): float {.benign.} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue