Re: Programming Challenge


[Prev][Next][Index][Thread]

Re: Programming Challenge



At 2:50 PM -0100 4/22/98, Steve Muckle wrote:
>I am trying to make a program  that will simulate a deck of cards for a
>collectable card game.  I would  rather lay out a set of numbers at the
>beginning (each number representing a  particular card) than pick them on
>the fly.  What my problem is is that I  need to get a list (or a matrix,
>it doesn't matter) of numbers 1 through 60,  randomly assorted, BUT no
>number appearing more than once.

The easiest way to do this is to first make an ordered list from 1-60, then
move the elements around randomly.  Here's the idea (I haven't checked this
on my calculator, but I've done this sort of thing before; this should
pretty close to correct). Spaces added for ease of reading.

seq(X,X,1,60,1) -> L1
For(A,60,2,-1)
 Int(A*rand)+1 -> B
 If B<A :Then
  L1(A) -> X
  L1(B) -> L1(A)
  X -> L1(B)
 End
End


 /      Darryl K. Nester        |  nesterd@bluffton.edu  \
/  Assoc. Prof. of Mathematics  |  Office: 419-358-3483   \
\       Bluffton College        |  Fax:    419-358-3232   /
 \  Bluffton, OH  45817-1704    |  Home:   419-358-9650  /


References: