[comp.sys.mac.hypercard] shuffling a stack

gphg1125@uxa.cso.uiuc.edu (Glenn P Hoetker) (02/07/90)

Is there a simple command that would shuffle the cards in a stack so that they
were in a random order?  If not, can someone give me pointers on a script
that would perform that function.    thank you.

Glenn Hoetker
g-hoetker@uiuc.edu

--
Glenn Hoetker
University of Illinois, Graduate School of Library and Information Science
g-hoetker@uiuc.edu     -or-   ghoetker@UIUCVMD

rieman@boulder.Colorado.EDU (John Rieman) (02/07/90)

In article <1990Feb6.193117.8068@ux1.cso.uiuc.edu> gphg1125@uxa.cso.uiuc.edu (Glenn P Hoetker) writes:
>Is there a simple command that would shuffle the cards in a stack so that they
>were in a random order?  

If you want any kind of performance at all, you'd be better off to 
shuffle a list of pointers to cards.  Of course, that means you have
to build a navigation routine that uses the pointers.

I've tried some schemes for shuffling lines in a field. One way is
to use the random function to select a line in sourceField, then put 
that line after destinationField (and delete it in sourceField).  When
there are no more lines to move, destinationField is a scrambled
version of sourceField.  The speed is not blinding, though.

-john
rieman@boulder.colorado.edu
U. of Colo.

jdevoto@Apple.COM (Jeanne A. E. DeVoto) (02/07/90)

In article <1990Feb6.193117.8068@ux1.cso.uiuc.edu>
gphg1125@uxa.cso.uiuc.edu (Glenn P Hoetker) writes:
>Is there a simple command that would shuffle the cards in a stack so that they
>were in a random order?

This command:
  sort by random(the number of cards)
-- 
====== jeanne a. e. devoto ========================================
 jdevoto@apple.com  |  You may not distribute this article under a
 jdevoto@well.UUCP  |  compilation copyright without my permission.
___________________________________________________________________
 Apple Computer and I are not authorized  |        CI$: 72411,165
 to speak for each other.                 |  AppleLink: SQA.TEST

dlugose@uncecs.edu (Dan Dlugose) (02/08/90)

In article <1990Feb6.193117.8068@ux1.cso.uiuc.edu> gphg1125@uxa.cso.uiuc.edu (Glenn P Hoetker) writes:
>Is there a simple command that would shuffle the cards in a stack so that they
>were in a random order?  If not, can someone give me pointers on a script
>that would perform that function.    thank you.

This should do, and probably not very slow.  Works if all cards are 
same background.

  -- first create new background field "neworder"
  put number of cards into n

  repeat with i = 1 to n
      put i into line i of cardlist
  end repeat

  repeat with i = 1 to number of cards
      put  random(n) into choice  -- choose a card to be number i in order
      put i into field neworder of card choice
      delete line choice of cardlist -- this card not eligible for reassignment
      subtract 1 from n -- 1 less card in list to choose from
  end repeat

sort by field neworder

Dan Dlugose
UNC Educational Computing Service

BARRY.CHERN@f200.n226.z1.FIDONET.ORG (BARRY CHERN) (02/09/90)

Glenn Hoetker asks:
>Is there a simple command that would shuffle the cards in a stack
  
This came up awhile back on CI$. Several people worked out different
elaborate methods, and then Sandy Melnik suggested the following:
     sort by random(the number of cards)
    
Pretty complicated, huh? You should look for Windoid #10 for a lot of
other sorting tricks.
 
** Origin : Aurora Borealis BBS - 614-471-6209 - 9600 HST - 1:226/200 **
 
 
^^^^^
The above statement expresses the views of the individual and does
not necessarily reflect the views or concerns of this place of origin.
 
--  
BARRY CHERN via cmhGate - Net 226 fido<=>uucp gateway Col, OH
UUCP: ...!osu-cis!n8emr!cmhgate!200!BARRY.CHERN
INET: BARRY.CHERN@f200.n226.z1.FIDONET.ORG

man@cs.brown.edu (Mark H. Nodine) (02/13/90)

In article <40716.25D319BB@cmhgate.FIDONET.ORG> BARRY.CHERN@f200.n226.z1.FIDONET.ORG (BARRY CHERN) writes:
>Glenn Hoetker asks:
>>Is there a simple command that would shuffle the cards in a stack
>  
>This came up awhile back on CI$. Several people worked out different
>elaborate methods, and then Sandy Melnik suggested the following:
>     sort by random(the number of cards)

Unfortunately, this does not quite do the trick, if you want a truly
random permutation.  The reason for this is that there are likely to be
many collisions, i.e., cards for which random gives the same value.  In
that case, my experience is that HyperCard always gives a stable sort, so
that the card that was first in the stack with a given random number will
be first in the sorted stack.  The probability that there will be no
collisions (in other words, that you will get good statistics) is 1/2 when
there are two cards (n=2), and it goes down exponentially from there, so
that by the time there are four cards, it is < 10%.  To get a distribution
that is closer to random, you could try 

   sort by random((the number of cards)^2)

or

   sort by random(the number of cards) && random(the number of cards).

	--Mark