On Mon, Jun 13, 2011 at 4:56 PM, michael rice <nowg...@yahoo.com> wrote:

> Is there an (existing) way to select 5 Ints randomly (no duplicates) from a
> population, say 1-20 (inclusive)?
>
> Michael
>

This is as close as I have gotten, but it is only probabilistically true.

take_n_unique_randoms_in_range :: ( Ord random
                                  , Random random
                                  , MonadIO io
                                  ) => Int -> (random, random) -> io
[random]
take_n_unique_randoms_in_range n (a,b) = liftM ((take n) . nub) .
(replicateM (3*n)) . liftIO $ randomRIO (a,b)

I'm going to put making an iteratee-based solution on my agenda.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to