How to randomly shuffle cards?
10 views (last 30 days)
Show older comments
So I have 4 decks of cards, and that means I have 208 cards. How to I make a program/function, such that once I start the program/function, it randomly shuffles once, and the cards are not shuffled until there are only 52 cards left. My main problem is to make the order of the randomly shuffled cards fixed, then continue using the order of the cards. When there are only 52 cards left, it should shuffle again, and the cards need to be fixed once again. I really have no idea on how to make this work. Thanks
0 Comments
Answers (2)
Cedric
on 27 Mar 2013
Edited: Cedric
on 27 Mar 2013
Look at the doc for RANDPERM.
You can use it to shuffle a set of 1 to N integers:
>> randperm(12)
ans =
5 8 10 1 9 11 3 7 12 6 2 4
but also e.g. for re-indexing a set of any type of elements..
>> cardsId = [3, 24, 54, 188] ;
>> shuffledCardsId = cardsId(randperm(numel(cardsId)))
shuffledCardsId =
188 3 24 54
0 Comments
Image Analyst
on 27 Mar 2013
Use randperm(). See what you can do with that.
2 Comments
Image Analyst
on 27 Mar 2013
You're not explaining this well at all. What does "then continue using the order of the cards." mean? I have no idea. What does "becomes permanent until only 52 cards are left." mean? If you want the order permanent, just quit - don't call randperm anymore. Why is the number going down from 208 to 52? What happens to the other cards? Where did they go? You did not say where they went or what happened to them. Are they discarded (removed from the pile)? If so, how? One at a time from the top? Removed from random locations within the deck? If you want specific help you need to explain what is happening in a lot of detail.
See Also
Categories
Find more on Communications Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!