Skip to content

Commit e234a35

Browse files
committed
factored pseudo-random formula into its own function
1 parent 6f066cb commit e234a35

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/algorithms/core.clj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,16 @@
1616
(def fib
1717
(map first fib-seq))
1818

19-
(def prng-seq
20-
(iterate (fn [x] (mod (+' (* 7 x) 5) 11)) 0))
19+
(defn- prngf
20+
"Pseudo-random number generating function, as in Essential Algorithms, Chapter 2"
21+
[x]
22+
(let [a 7 ;; magic constants; TODO: do better
23+
b 5
24+
m 11]
25+
(-> x
26+
(* ,,, a)
27+
(+' ,,, b)
28+
(mod ,,, m))))
29+
30+
(def rnd
31+
(iterate prngf 0))

0 commit comments

Comments
 (0)