[Haskell-beginners] [Haskell-cafe] select :: [(Float, a)] -> a -- Weighted stochastic selection - help?

Tim Millea tim at millea.com
Fri Sep 5 12:54:32 EDT 2008

I am already using the following function

  pickOne xs g = (xs !! r, g')
     where (r, g') = Random.randomR (0, length xs - 1) g

but I need to weight the items in the list, e.g. [(0.1, 'a') , (0.9, 'b')]
for stochastic selection in a purely functional way, i.e. no monads. Any
ideas welcome. 


More information about the Beginners mailing list