Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

Card Shuffling Program.

$
0
0
I have no idea where to put this.
I was wondering how hard it would be to make a card shuffling program.
I want it to be truly randomized.
Here's a quick example for a 5 card deck:

There are 5 slots so:

[ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ]

and 5 cards:

[ A ] [ B ] [ C ] [ D ] [ E ]

and the true randomization im thinking about would go like this:

A Random number between 1 and 5 is generated for card A, this will be it's slot. And so on for B,C,D and E.

What common sense would say is that A gets a chance at 5 slots and B gets a chance at 4 slots and C,3 etc.

But to me that's not true randomization.

I want a program that shuffles it this way. A,B,C,D and E. Get the same chance at the same slot. It may end up like this:

[ 1A ] [ 2E ] [ 3 ] [ 4D ] [ 5 ] - with B and C being replaced. And being left to the side so to speak with no slot. Because they were replaced.

But this would be stage 1 of the shuffle. Next a number would have to be assigned to A,E and D. 1 for the number of times it successfully had a chance of entering the deck without being replaced.

Next E,D,C,B and A would be rolled again in that order and it would say end up perfect like this, so to speak:

[ 1D ] [ 2A ] [ 3C ] [ 4B ] [ 5E ]

The program would then assign the number to the cards again. A-2 B-1 C-1 D-2 E-2.

This is where the real randomization I want takes place. Since A,D and E have now entered the deck twice succesfully. The process has to be repeated until each card has finally had the exact same number of successful deck entries. Reversing "Roll" order each time.

How would one go about doing this and would it be difficult? If that would take too long to load I would understand. The number of times it would have to rinse and repeat would be astronomical.

If that were the case then a simple "Each card gets an equal roll at a spot until finally it rolls each card into its own slot" would be fine.

How would I go about doing 1 or the other?
And what are your opinions on this?

Viewing all articles
Browse latest Browse all 2703

Trending Articles