Shuffling

now what I was gunna say before my browser went screwy.
how could you possibly ‘predict’ my post example?

you run that code once, twice, three times, they’re all different. That means somewhere in the world. Somebody trying to sync their generator to the seed of the random() their code is going to produce a different result.

Even being that it’s based on a random number between 0 and 52, sure there are limited numbers of output. But being that it makes sure it never reuses the same index before placing the card back in the deck makes it very hard to predict the actual output… by any ‘algorithm’.
Now I’m definitely not the greatest programmer in the world. But it seems so farfetched that a person (or code) could predict:
a) the randomly generated number (more possible)
b) the next number to be placed in ‘used’ (less possible)

Of course, we all program to learn (or make money) so please, if I am wrong, I wanna know why =)

make an array of 52
assign a random number between 1 a 100000 to each entry
assign the first card to the highest number, the second card to the second highest number, etc.

     I am just a poker player who is researching RNG integrity as it relates to my online poker play.I have no programming experience nor a high education.I have been playing on pokerstars for 3 yrs and have been suspect of the randomness for a long time.Most arguments in this area are about other players being able to predict the rng and act accordingly to win.Thus, all this hullaballoo on how to create a truly random shuffle to nullify these hackers attempts to steal me hard earned dollars.All of this seems to me to be smoke in eyes of the masses.Corruption has always been seeded at the top of the food chain and not us lowly joe's tryin to make a buck to feed our families and pay our bills.I am far more concerned about corruption at the highest levels within my arena, ie, Pokerstars, Intel, and the 2 companies that certified their RNG.Even if pokerstars itself has no part in this conspiracy theory, although they clearly stand to benefit the most from the ability to control cards dealt to players and when, the 2 companies they hired to verify integrity of their Intel RNG were given all their source code and means of seed generation, meaning those employees who performed such tests could take that information and develop code to create an ATM for themselves via pokerstars and/or its players.As for Intel, if they are out to screw us then we are all lost.I could go on and on about my conspiracy theories as to Pokerstars and how they do it, but I really only wanted to make two points about all that I have read here as it relates to online poker,  the shuffle, and collusion:
  1. Being that the cards are dealt one at a time to the players in a circular motion, if the cards are too random in a shuffled deck about to be dealt, wouldn’t that be creating a greater likelihood of players getting dealt pairs and suited connectors, and that those same cards would fall on the ensuing flop, turn, and river? ie trips, flushes, 2 pairs, and full boats.Like if all four aces were stuck together at the top quarter of the deck then 4 out of 9 or 10 players would receive one ace and a random card, not pocket aces.I think that these decks are over-shuffled and that is creating these common instances of pocket rockets, trips, full houses, and quads even.Ive seen quads way to many times.This also creates a much more exciting game for the players.We all want to hit those big hands, not just win playing a solid hand.It would seem like a win win scenario for all involved to taint the rng just enough to make play more exciting at their website verses another… right? I ask questions I already know the answer to, I just wonder if anyone agrees with me.

  2. If Pokerstars, or any other online gaming site, its employees and programmers, were out to control the game and the outcomes for profit, above and beyond that which they already make with the odds in their favor, then who would know it? Who could prove it? Who could stop it?
    Who would even care except for the idiots like myself who keep playing the machine believing its fair and random and that I just need to improve my play ?

    Lastly, I just want to say that overall I have made more money than I have lost playing online poker and should be the last person to raise these questions or even care, but I really feel as though something is wrong with the RNG that I have been intimate with for many years and if so, then that is wrong,whether or not it has negatively affected me.I feel that these RNG’s should be built by and subject to the scrutiny of people like yourselves, much as how Linux flavors have been developed and scrutinized by the knowing public and not a private multi-million dollar company who’s employees cant be trusted, nor the CEO, who would gladly take a % or a payoff to say the RNG is good.

when writing a card dealer are there any requirements other than:

  1. not predictable
  2. during a hand don’t deal the same card twice :wink:
  3. the cards should be dealt randomly

perfect shuffle in perl :

sub shuffle {
my @a = ();
my @b = ();

return @_ if (@_  2);

for (@_) {
    if (random_bit()) {
        push @a, $_;
    } else {
        push @b, $_;
    }
}

return (shuffle(@a), shuffle(@b));

}

This is similar to the radix sort algorithm with random numbers.

random_bit returns a boolean. This bit can be read from /dev/random for true randomness on linux.

Very cool app. Can you tell me where to download the Help files? Apparently they didn’t make it during the install process, so it won’t load them. Thanks!

Thank you very muCh

Thanks for addressing this issue so quickly, Dr. Lessig. I thought something was fishy in that article.

So the OrderBy criteria:

  • var shuffledcards = cards.OrderBy(a => Guid.NewGuid());
    is basically equivalent to
  • Random rand = new Random()
  • var shuffledcards = cards.Sort((a,b) => rand.Next(0,2) == 0 ? -1 : 1);
    since a new guid is created on every comparison. So it’s basically sorting with every Compare returning a random result - which isn’t the same as the sort Eric mentioned - it will likely be biased based on the sorting algorithm used.

thank you was a useful article…

Thanks a load for the stats. Haven’t seen anything nearly as comprehensive or useful anywhere else.

I can’t wait for the day when web design programs are as easy as layout programs for print!

how can i divide the deck into three parts and then shuffle them?

A possible source of randomness that is available to everyone is environmental RF noise. This can be sampled off of the line input from the sound card. Best if it is hooked up to a radio between AM stations, but even with nothing plugged into it, there is usually a little noise. In an actual casino, a microphone may be a good source as well. What is needed is a real world (as opposed to computed) source because the real world is not predictable. Sample this several times, and combine the results into a seed.

Not quite radioactive decay, but pretty good for the price.

Any algorithum is going to be predictable where are “random” numbers should be unpredictable. So there is a problem right there.

Sampling noise and mouse click helps makes the output more unpredictable, thus the resulting number should be unpredictable.

Of course there are many ways to shuffle cards. Throw all cards on table and move them around with your hands. Stack, cut and deal. You could also try to mimic that behavior and consider the deck shuffled.

There is also probabilities to be considered. If decks are shuffled, probability says 1/52 chance of first card being an Ace of Spades. Now you may shuffle a thousand times and not get an Ace of Spades as the first card, but with a large amount of attempts (and I do mean large), the percentage should converge to 1/52. Otherwise, someone may think your shuffle is rigged.

So not only does you shuffle have to be random, but its results should converge to known probabilities over time.

Two thoughts that are being addressed here:

  1. If you are doing anything you care about, research the random number generator (PRNG) you are using. The best ones will have passed a number of theoretical tests to deterimine that they indeed have no pattern. Fun to note that one of the quick litmus tests is to generate a large number of 5-card poker hands and see how the result aligns to computed probabilities.

  2. Using noise and other environmental sources is tempting. However, I think this creates a maintenance burden to ensure that the quality of the random number stream is high and stays high!

As others have said, the problem with Random is often the seed. .NET’s random number generator is pretty decent if you use an unpredictable seed:
Random rand = new System.Random(Guid.NewGuid().GetHashCode());

For something like online gambling where significant money’s involved, the crypto RNG would be better. In that case, you’ll need to give up on a one-liner (unless it’s one unreadable line), since the RNG returns an array of bytes.

http://msdn2.microsoft.com/en-us/library/system.security.cryptography.rngcryptoserviceprovider.aspx

I know this is a late comment, but I have something to add to this. I don’t have experience with deck shuffling algorithms, however I can’t really see much problem here. Even though random and psuedo random coding is sketchy at best, when it comes to deck shuffling, it shouldn’t be difficult to figure out how to randomize the deck.

Take real world shuffling with the hands, you roughly cut the deck in half, then attempt to merge them so that the deck is in staggered as perfectly as possible. However in real life it doesn’t happen with perfection, and therefore there are always a few to several cards that are “misplaced” in the pattern. repeat until one is “comfortable” with the randomized nature of the deck.

One could simply emulate this with a few random routines. Literally randomly deciding which is the next card to merge into the new deck from the split decks.

If one loops the deck through something like this, the results should be staggeringly more random than initially suspected.

dim deck
for i = 0 to 12

main(

I would like to have a preview first, I hit the post button accidentally while writing thise. Though I suppose I should have written in a text editor first.

I don’t think you need the rest to understand what I mean though.