Coder Social home page Coder Social logo

prd's Introduction

PRD

A JS library for generating pseudo-random distribution.

What is PRD?

from the Dota 2 Gamepedia page:

The uniform or true random distribution describes the probability of random event that underlies no manipulation of the chance depending on earlier outcomes. This means that every "roll" operates independently.

The pseudo-random distribution (often shortened to PRD) in Dota 2 refers to a statistical mechanic of how certain probability-based items and abilities work. In this implementation the event's chance increases every time it does not occur, but is lower in the first place as compensation. This results in the effects occurring more consistently.

The probability of an effect to occur (or proc) on the Nth test since the last successful proc is given by P(N) = C ร— N. For each instance which could trigger the effect but does not, the PRD augments the probability of the effect happening for the next instance by a constant C. This constant, which is also the initial probability, is lower than the listed probability of the effect it is shadowing. Once the effect occurs, the counter is reset.

TL;DR it keeps random-based occurences from games from being luck-based. PRD increases the chances of occuring whenever the random chance fails to occur.

How to use

Importing

for client-side JS

    <script type="text/javascript" src="/path/to/prd.js"></script>

for NodeJS

    const PRD = require("prd").default;

for ES6

    import PRD from "prd";

Creating a PRD

The PRD constructor takes a number value, namely "chance", which is in the range of 0 to 1

    let prd = new PRD(0.25);

Generating success

    const success = prd.next();

What the PRD can do is that if you call the next() method, it tells whether the next result would be a fail or a success. Once the PRD successes, the PRD progress will reset back to 1, since the succession is based from P(N) = N*C where N is the number of attempts and C is the constant, calculated from the given chance. (see the wikipedia page.)

Resetting

    prd.reset();

prd's People

Contributors

lxsmnsyc avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.