application/octet-stream
•
858 B
•
28 lines
;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;; This project uses the MIT license, a copy should be included under /LICENSE
[def random/seed 0]
[defn random/seed-initialize! []
[set! random/seed [bit-xor [time] [time/milliseconds]]]]
[defn random/rng! []
[set! random/seed [+ 12345 [* random/seed 1103515245]]]
[bit-or [bit-shift-left [bit-and random/seed #xFFFF] 16]
[bit-and [bit-shift-right random/seed 16] #xFFFF]]]
[defn random/seed! [new-seed]
"Set a new seed value for the RNG"
[set! seed new-seed]]
[defn random/seed []
"Return the current RNG seed value"
seed]
[defn random [max]
"Return a value from 0 to MAX, or, if left out, a random int"
[if [numeric? max]
[rem [abs [random/rng!]] max]
[random/rng!]]]
[random/seed-initialize!]