MathGroup Archive 1994

[Date Index] [Thread Index] [Author Index]

Search the Archive

Generating Lottery Numbers

  • To: mathgroup at
  • Subject: [mg366] Generating Lottery Numbers
  • From: Xah Y Lee <xyl10060 at>
  • 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 


LotteryGenerator[ sea_Integer, fish_Integer] :=
   Module[{n, mylist = {} },
       While[ Length[mylist] < fish, 
           n = Random[Integer, {1,sea}];
           If[ !MemberQ[mylist, n], AppendTo[mylist,n] ]
   ]/; (sea >= fish)


 Xah Lee   xyl10060 at| 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                 |

  • Prev by Date: Re: Combining pure functions..
  • Next by Date: Re: Unique List
  • Previous by thread: Re: Mutiple delete in lists
  • Next by thread: Re: Simple Solve Question