Comments (7)
I know, I use Fisher-Yates a lot. The point here is to have it realistic: the more you shuffle the deck, the more random it gets - just like in the real world.
You could make another module for card games, when you need better randomness. These modules will become external and you can choose which ones to load in the near future.
Thanks anyway, I will keep this open until it haves Fisher-Yate as an option.
from deck-of-cards.
Ah ok. I was mostly worried that somebody would make a card game out of this expecting the shuffle to be unbiased. I get the feeling most programmers would look at your shuffle code and not see any problems.
from deck-of-cards.
I was thinking that I should add a parameter to the shuffle -function:
deck.shuffle(true) // realistic shuffle
deck.shuffle() // Fisher-Yates
from deck-of-cards.
Reference:
https://www.npmjs.com/package/knuth-shuffle
https://github.com/coolaj86/knuth-shuffle
from deck-of-cards.
When shuffling two times (like in the Deck of Cards example), I'm getting equal results as with Fisher-Yates:
function shuffle(array) {
array.sort(function() {
return Math.random() - .5;
});
array.sort(function() {
return Math.random() - .5;
});
}
http://bost.ocks.org/mike/shuffle/compare.html
So I might as well use Fisher-Yates since it's much faster.. :)
Thanks for sharing the link!
from deck-of-cards.
Oooh interesting. On Chrome, the old algorithm has a nice solid green streak down the diagonal, and in Safari it does something weird with the top row, but on both of them running the old shuffle twice looks pretty unbiased. I wonder why.
I love this problem, I find it really interesting for some reason.
from deck-of-cards.
Yeah, the problem itself is very random but the results not so much :D
from deck-of-cards.
Related Issues (20)
- How can I know which card I clicked? HOT 1
- card.flip is not a function HOT 1
- Why does poker() not return the cards that were dealt? HOT 3
- TCG use? HOT 7
- University offer HOT 1
- Cards flip to top- and backside randomely HOT 1
- new version HOT 3
- Jokers HOT 5
- open source? HOT 59
- Italian Version deck HOT 8
- SUGGESTION: Removing cards from deck before shuffle HOT 1
- SVG only cards - https://cardmeister.github.io/ HOT 2
- Feature Request: Add multiple decks HOT 3
- Multiplayer: Everyone can see all cards, Any future release on this ? HOT 4
- Source link in app HOT 2
- Ability to shuffle specific piles of cards HOT 3
- Can I create a different deck? HOT 1
- Multiplayer shuffle of double deck produces consistient deck result HOT 1
- Can drag to select multiple cards?
- New version open source
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deck-of-cards.