[Fluxus] picking a function with weights
    gabor papp 
    gabor.lists at mndl.hu
       
    Tue Feb  2 06:34:54 PST 2010
    
    
  
hi,
> I generally do weighting by duplicating list elements, but there must be
> a better way?
i would do it with an associative list like this. maybe there's even a 
better way.
define (choose l)
   (let ([r (rndf)])
       (display r)(newline)
       (cdr (assf (lambda (x) (>= r x)) l))))
(define funcs
   (list
     (cons .8 (lambda () (display "one")))
     (cons .7 (lambda () (display "two")))
     (cons .4 (lambda () (display "three")))
     (cons .2 (lambda () (display "four")))
     (cons .0 (lambda () (display "five")))))
((choose funcs))(newline)
the assf expression goes through the list and returns the first element 
whose car is not less then the random number. so there are ranges 
instead of weights in car fields of the list:
1.-.8, 8.-.7, .7-.4, etc.
best,
gabor
    
    
More information about the Fluxus
mailing list