Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!brunix!man From: man@cs.brown.edu (Mark H. Nodine) Newsgroups: comp.sys.mac.hypercard Subject: Re: shuffling a stack Message-ID: <28957@brunix.UUCP> Date: 12 Feb 90 22:02:36 GMT References: <40716.25D319BB@cmhgate.FIDONET.ORG> Sender: news@brunix.UUCP Reply-To: man@cs.brown.edu (Mark H. Nodine) Organization: Brown University Department of Computer Science Lines: 26 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