Generating Lottery Numbers
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg366] Generating Lottery Numbers
- From: Xah Y Lee <xyl10060 at fhda.edu>
- Date: Tue, 27 Dec 1994 12:29:50 -0800 (PST)
Robert B. Love wrote >... 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... Here is a "down-to-earth" method. Hope somebody can show us an elegant mma solution. Clear[LotteryGenerator] LotteryGenerator[ sea_Integer, fish_Integer] := Module[{n, mylist = {} }, While[ Length[mylist] < fish, n = Random[Integer, {1,sea}]; If[ !MemberQ[mylist, n], AppendTo[mylist,n] ] ]; mylist ]/; (sea >= fish) -- (*example*) LotteryGenerator[42,6] -- Xah Lee xyl10060 at tiptoe.fhda.edu| Quote of the day: Mathematician of WasaMata U. | I'd rather attract women than Visiting Scholar of PoDunk U. | being attracted by strange attractors. Professor Emeritus of Standard U. | --Some Scholar of PoDunk U. Mountain View, CA |