weighted-selection   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/runtime/scheme.xtm

Implementation

(define (weighted-selection . args)
   (let ((rand (random)))
      (let loop ((lst args)
     (count 0))
   (if (< rand (+ count (caar lst)))
       (cdar lst)
       (loop (cdr lst) (+ count (caar lst)))))))


Back to Index