[Haskell-cafe] Acquiring a random set of a specific size (w/o dups) from a range of Ints
nowgate at yahoo.com
Tue Jun 14 04:31:29 CEST 2011
It seemed like something like this should exist in a prob/stat package, and if so, didn't want to reinvent the wheel.
Shuffle [1..20], then take 5?
Yes, so simple, I'm embarrassed I didn't think of it.
--- 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 ,
sampleSubset :: MonadMC m => [a] -> Int -> m [a]
Complete example code for your example:
evalMC (sampleSubset [1..20] 5) (mt19937 0)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe