Re: Shuffling a linked list



Hi Robert,

Robert Maas, see http://tinyurl.com/uh3t wrote:
From: "A. Farber" <Alexander.Far...@xxxxxxxxx>
I have a doubly-linked list of 32 playing cards, which I'd like
to randomly and evenly (!) shuffle.

Why only 32 instead of the usual 52? (Just curious.)

it's a russian card game, similar to german skat:
http://en.wikipedia.org/wiki/Preferans
You probably get too many poker questions here in the group :-)

Without some additional API, such as a tool for removing an element
from somewhere, the task cannot be accomplished. Initially you have
32 cards in the list, and if you use either insert tool even once
you now have 33 cards in the list, and there's no way to ever get
back to 32.

Of course I have macros for removing and replacing elements too.

Try this instead: Start with k0=0 k1=n. Generate rand(k1) and move
*that* element to the top of the list. Now increase k0 and decrease
k1, and compute the rand(k1) again, but skip the first k0 elements
and select randomly only from the remaining elements, i.e. move
element# k0 + rand(k1) to top. Each time you select from fewer
elements from the end of what you've already chosen (now topmost
segment) to the very end. When you're down to just one remaining
element not yet selected (k0=n-1 k1=1), you're done already.

Hmm I think that will always move the lowest cards to much down...

Regards
Alex

--
http://preferans.de

.



Relevant Pages

  • Re: Either there is a God of infinite intelligence
    ... creation event and plenty that contradicts it. ... >The DNA code refers to mathematics and probability regarding evolution. ... out the cards in their new order, ... the odds of even one shuffle ending up being the same as ...
    (talk.origins)
  • Re: The mathematical probability of evolution creating a simple 200 part system
    ... Evidence clearly shows that life has evolved over an extensive period ... >The DNA code refers to mathematics and probability regarding evolution. ... out the cards in their new order, ... the odds of even one shuffle ending up being the same as ...
    (talk.origins)
  • Re: Rules FAQ
    ... The task of a tournament is to unshuffle the cards into rank order. ... There are many decisions to make concerning: how many Rounds ... players are in the tournament, the initial rank distribution of the ... the "riffle shuffle" is also defective in tending ...
    (rec.games.go)
  • Re: Card dealing and random repetition
    ... and inspiring for an 'elegant' way to simulate a shuffle. ... The dealer divide the deck in two parts, trying to make them equally big (but I estimate the error margin being between 1 to 5 cards from the count of 26 cards per half-deck). ... adding a random probability of the next card on the array being picked instead of the next of the other array. ...
    (comp.programming)
  • Shuffling without Swapping
    ... A common algorithm for shuffling a deck of cards is: ... can be used to shuffle such sequences of any length. ... In general, swapping means copying A to B and copying B to A. However, ...
    (sci.crypt)