[Numpy-discussion] Generating random samples without repeats

Robert Kern robert.kern@gmail....
Thu Sep 18 17:00:12 CDT 2008

On Thu, Sep 18, 2008 at 16:55, Paul Moore <pf_moore@yahoo.co.uk> wrote:
> I want to generate a series of random samples, to do simulations based
> on them. Essentially, I want to be able to produce a SAMPLESIZE * N
> matrix, where each row of N values consists of either
> 1. Integers between 1 and M (simulating M rolls of an N-sided die), or
> 2. A sample of N numbers between 1 and M without repeats (simulating
>    deals of N cards from an M-card deck).
> Example (1) is easy, numpy.random.random_integers(1, M, (SAMPLESIZE, N))
> But I can't find an obvious equivalent for (2). Am I missing something
> glaringly obvious? I'm using numpy - is there maybe something in scipy I
> should be looking at?

numpy.array([(numpy.random.permutation(M) + 1)[:N]
    for i in range(SAMPLESIZE)])

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco

More information about the Numpy-discussion mailing list