Re: Unique List
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg365] Re: [mg358] Unique List
- From: Richard Mercer <richard at seuss.math.wright.edu>
- Date: Tue, 27 Dec 1994 14:00:53 -0500
> OK, time for a little fun. I can generate a list of
> random integers as Table[Random[Integer,{1,42}],{6}]
> and I get a list 6 elements long containing the integers
> from 1 to 42. But how do I make sure no elements are
> repeated.
>
> I'm trying to simulate a lottery pick of 6 numbers between
> 1 and 42 but no repeats are allowed. Any clever tricks
> to get a list with no members repeated?
>
> Thanx, Good Luck and Happy New Year to all.
One good way, which gives equal probability to all results (assuming
RandomPermutation does what I think):
<<DiscreteMath`Combinatorica`
Sort[Take[RandomPermutation[42],6]]
{10, 18, 22, 24, 33, 41}
Richard Mercer