On Dec 3, 2008, at 17:45, Mark H. wrote:
> I have the feeling that the "right interface" for a single stream of
> pseudorandom numbers is a seq, rather than a "function" that you
> call.
I'd provide two interfaces:
1) Low-level: (rng seed) yielding a pair [random-number, new-seed]
2) High-level: (random seed) yielding an infinite (obviously lazy)
seq of the random numbers obtained starting from the given seed.
What I consider important is the explicit specification of the seed,
which means that the code always says explicitly where its random
number sequence starts from.
I just happen to have those two functions in the example section of
my monad implementation, as rng works nicely in the state monad:
(defn rng [seed]
(let [m 259200
value (/ (float seed) (float m))
next (rem (+ 54773 (* 7141 seed)) m)]
(list value next)))
(defn random [seed]
(let [[value next] (rng seed)]
(lazy-cons value (random next))))
This particular implementation of rng is probably not a good one
(it's the first algorithm I found), but my point here is the
interface, not the algorithm.
Konrad.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---