Giter Club home page Giter Club logo

gamblers-dice's Introduction

The Gambler's Fallacy Dice

The term Gambler's fallacy refers to a misconception about statistics. [...] In statistics, a random event has a certain probability of occurring. The fallacy is that if the event has occurred less frequently in the past, it will be more frequent in the future. -Wikipedia

Well no longer is this a fallacy my friends, these dice are real! If you roll a 20 sided die, and you haven't seen a 20 in a while it is statistically more likely to show up in the next roll with these dice. And the best part, it's still uniformly random for large sample sets!

obligatory chart a stupid chart

How to Use

$ npm install --save gamblers-dice
const RiggedDie = require('gamblers-dice')
const die = new RiggedDie(20) // for a d20

console.log(die.roll()) // 1 -> 20
console.log(die.roll()) // keep using the same instance

Other Languages

The community has ported this to Java (@eukaryote31), Elm (@solkaz), Python (@torvaney), and C# (@MrTarantula). Check them out if these are your languages of choice!

I don't get it

Normally when rolling a 4 sided die, you would have a 25% chance of rolling any given face, at any time. If you rolled a 4, three times in a row it doesn't make it any less probable of happening the next time. Further, a 1 is not "more likely" because "it hasn't been rolled in a while".

This library breaks that standard rule.

Roll % of 1 % of 2 % of 3 % of 4 Actual Roll
1 25% 25% 25% 25% 1 (⚀)

In the above example, we got out our fancy die from its box, and rolled. Because we are gods, we know the probability of each side being rolled, and see nothing amiss. Every face has a 25%, and we randomly roll a 1.

Roll % of 1 % of 2 % of 3 % of 4 Actual Roll
2 14% 29% 29% 29% 2 (⚁)
3 22% 11% 33% 33% ?

Whoa, that's different, we are now 11% less likely to roll a 1, and indeed, by luck, we don't. We instead roll a 2, and when we do, we see the probabilities shift yet again. Let's roll the die a couple more times.

Roll % of 1 % of 2 % of 3 % of 4 Actual Roll
3 22% 11% 33% 33% 3 (⚂)
4 30% 20% 10% 40% 1 (⚀)
5 9% 27% 18% 45% ?

After four rolls, we've yet to see a 4, it is obviously due and indeed there is now a 45% chance of rolling a 4. If you were going to do something rash (like bet on a 4) now would be the time.

This is stupid, why did you make this

I made a chatbot that rolled dice, and it was constantly criticized for being "broken" because four 3's would come up in a row.

These accusations would come up even though they (all being computer science majors) know it's possible (although unlikely) for these events to happen. They just don't trust the black box.

“Scientists have calculated that the chances of something so patently absurd actually existing are millions to one. But magicians have calculated that million-to-one chances crop up nine times out of ten.”

― Terry Pratchett, Mort

gamblers-dice's People

Contributors

cletusw avatar jasonaheron avatar mrtarantula avatar preco21 avatar sataaa avatar torvaney avatar xori avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gamblers-dice's Issues

Rolling a zero is possible

Math.random() could give 0 in which case steps is 0 and the subsequent loop would never run; therefore target would still be 0.

Changing the loop condition to steps >= 0 fixes this issue.

Ensure your entropy

Me? I am a data scientist for a company that makes slot machines. I know a thing or two about probabilities. I freaking love this. I can see a game being made using this. Not a gambling game, because it would never get past even the most easily bought off federal compliance officer in the land. However, regular games could benefit from this mechanism. A system where you luck is always turning on you...

Also, to ensure your odds, you need very high entropy. Sure, go ahead and use your mersene twister. Its the defacto default. However, if you ever go live with something that depends upon this for millions of game sessions (hey, think BIG), then use any one of several schemes to insure the entropy is excellent. Like sigma 15 excellent.

You can mark this closed. Its just a suggestion! Good work!

Make repeats less likely

I think it would be even better if rolling a 3 would make it less likely that the next roll would be a 3, and rolling two 3s would make it even less likely to roll a third, etc. This should still keep it uniformly random over time but would make it marginally funnier.

true uniformity

You could populate each side like a deck of cards...

1000 1's
1000 2's
1000 3's

Then, when people rolled, eventually they would reach true uniformity (in this example after 3000 rolls)

Maybe have this accessible by a different "engine" property, (or "algorithm", or "sampleType" or whatever you want to call it)

You could also pick the initial sample size (aka, reaches uniformity every 1000, or every 10, or every 100).

This would allow people to 'count cards' in a sense ( count die ).
Just an idea!

And, people would think "I haven't rolled 3 in a while", they'd be right to think that because there are a lot of 3's left in the "deck".

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.