On Dec 4, 9:07 am, "don.aman" <[EMAIL PROTECTED]> wrote:
> Since we're being all high-level, it'd be good for a random function
> which allows us to specify the range of numbers, since % doesn't
> promise an even spread of probabilities (especially for large ranges).
Not sure if I understand the second part (% an even part), but I
realized that
a random function for a specific range of numbers can be written using
the
lazy example in this thread. (I earlier got stuck trying to use (cycle
(rand-int 10))
for that.
(defn lazy-rand-vect
"a lazy cycle of random elements taken from a vector."
[vector]
(lazy-cons (nth vector (rand-int (count vector))) (lazy-rand-vect
vector)))
example:
(def amino_acids 21)
(def virus_length 1000)
(defn make-virus
"Creates a virus of length virus_length"
[]
(apply str (take virus_length (lazy-rand-vect (apply vector (map #
(char (+ 65 %)) (range 10))))))
; old way also worked, but lazy-rand-vect I can use for a few other
things as
well.:
;(apply str (take virus_length (map #(char (+ (rand-int amino_acids)
65 %)) (cycle (list 0))))))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---