GithubHelp home page GithubHelp logo

Comments (7)

pakastin avatar pakastin commented on May 7, 2024

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.

agrif avatar agrif commented on May 7, 2024

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.

pakastin avatar pakastin commented on May 7, 2024

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.

Marak avatar Marak commented on May 7, 2024

Reference:

https://www.npmjs.com/package/knuth-shuffle
https://github.com/coolaj86/knuth-shuffle

from deck-of-cards.

pakastin avatar pakastin commented on May 7, 2024

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.

agrif avatar agrif commented on May 7, 2024

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.

pakastin avatar pakastin commented on May 7, 2024

Yeah, the problem itself is very random but the results not so much :D

from deck-of-cards.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.