[Haskell-cafe] Acquiring a random set of a specific size (w/o dups) from a range of Ints

michael rice nowgate at yahoo.com
Thu Jun 16 20:04:44 CEST 2011

I seem to still be missing some things. I found mt19937 in GSL.Random.Gen, but there are two evalMCs, one in Control.Monad.MC and another in Control.Monad.MC.GSL. Which?
Registering monte-carlo-0.4.1...Installing library in /home/michael/.cabal/lib/monte-carlo-0.4.1/ghc-7.0.2Registering monte-carlo-0.4.1...[michael at sabal ~]$ ghciGHCi, version 7.0.2: http://www.haskell.org/ghc/  :? for helpLoading package ghc-prim ... linking ... done.Loading package integer-gmp ... linking ... done.Loading package base ... linking ... done.Prelude> :m + Control.Monad.MC.ClassPrelude Control.Monad.MC.Class> evalMC (sampleSubset [1..20] 5) (mt19937 0)
<interactive>:1:1: Not in scope: `evalMC'
<interactive>:1:34: Not in scope: `mt19937'Prelude Control.Monad.MC.Class>
--- On Mon, 6/13/11, Felipe Almeida Lessa <felipe.lessa at gmail.com> wrote:

From: Felipe Almeida Lessa <felipe.lessa at gmail.com>
Subject: Re: [Haskell-cafe] Acquiring a random set of a specific size (w/o dups) from a range of Ints
To: "michael rice" <nowgate at yahoo.com>
Cc: haskell-cafe at haskell.org
Date: Monday, June 13, 2011, 9:38 PM

On Mon, Jun 13, 2011 at 8:56 PM, michael rice <nowgate at yahoo.com> wrote:
> Is there an (existing) way to select 5 Ints randomly (no duplicates) from a population, say 1-20 (inclusive)?

Yes, already implemented in the monte-carlo package as sampleSubset [1],

  sampleSubset :: MonadMC m => [a] -> Int -> m [a]

Complete example code for your example:

  evalMC (sampleSubset [1..20] 5) (mt19937 0)


[1] http://hackage.haskell.org/packages/archive/monte-carlo/0.4.1/doc/html/Control-Monad-MC-Class.html#v:sampleSubset

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110616/8d12d1db/attachment.htm>

More information about the Haskell-Cafe mailing list