From Newsgroup: comp.lang.lisp
Pascal J. Bourguignon wrote:
(loop with repeatitions = 1000000
with R = 16
with counts = (make-array 16 :initial-element 0)
repeat repeatitions
for x = (random R)
do (incf (aref counts x))
finally (return (map 'vector
(lambda (count) (/ count (float repeatitions 1.0d0)))
counts)))
#(0.062412D0 0.062663D0 0.062758D0 0.062578D0 0.062252D0
0.063027D0 0.06256D0 0.062532D0 0.062121D0 0.062455D0
0.06234D0 0.062332D0 0.062452D0 0.062679D0 0.062388D0
0.062451D0)
Gauche Scheme
(use srfi-27) ;; random-integer
(let* ((repetitions 999888)
(R 16)
(counts (make-vector R 0)))
(dotimes (repetitions)
(inc! (vector-ref counts (random-integer R))))
(vector-map (lambda (count) (/. count repetitions)) counts))
#(0.06247299697566128 0.06231297905365401 0.06204594914630439
0.06241299025490855 0.06288204278879235 0.06297105275790889
0.06264001568175635 0.06237098555038164 0.06261601299345526
0.06260501176131726 0.06279903349175107 0.061806922375306036
0.06269802217848398 0.06236298465428128 0.06279203270766326
0.06221096762837438)
--
The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2