Janet Notes and Examples

Math and Random Numbers

See (doc "math/").

(math/random)  #=> random num from 0 to < 1.

# To get a new and different rand each time through, do
# this first.
(math/seedrandom (os/cryptorand 8))

(math/round 4.6)  #=> 5

# To round to `n` decimal places:
(defn round-places
  ``Arg `n` should be an integer > 0.``
  [x n]
  (let [m (math/pow 10 n)]
    (/ (math/round (* x m))
       m)))

(round-places 4.123 2)  #=> 4.12