Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Card Shuffling Program.

iPitOmeiPitOme Posts: 2Member
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?

Comments

  • iPitOmeiPitOme Posts: 2Member
    I may have just asked for the same thing twice...
    Maybe all I'd need is for the program to roll eventually until it finally got one where none were replaced. And displayed the results.
Sign In or Register to comment.