{"id":28489234,"url":"https://github.com/fschaefer/probability.js","last_synced_at":"2025-10-28T22:14:37.754Z","repository":{"id":5103167,"uuid":"6266793","full_name":"fschaefer/Probability.js","owner":"fschaefer","description":"Probability.js makes it easy to call JavaScript functions by probability in Node.js and the browser.","archived":false,"fork":false,"pushed_at":"2023-05-23T11:04:00.000Z","size":147,"stargazers_count":166,"open_issues_count":2,"forks_count":15,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-06-09T01:58:48.969Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"othree/markdown-syntax-zhtw","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fschaefer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-10-17T19:00:46.000Z","updated_at":"2025-04-05T12:46:20.000Z","dependencies_parsed_at":"2023-07-06T21:46:36.405Z","dependency_job_id":null,"html_url":"https://github.com/fschaefer/Probability.js","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":0.4444444444444444,"last_synced_commit":"51bb5d20e07a96368ce002cebf6b4a9ee8746cec"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fschaefer/Probability.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2FProbability.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2FProbability.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2FProbability.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2FProbability.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fschaefer","download_url":"https://codeload.github.com/fschaefer/Probability.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2FProbability.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262693208,"owners_count":23349693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-08T06:36:13.099Z","updated_at":"2025-10-28T22:14:37.659Z","avatar_url":"https://github.com/fschaefer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Probability.js Logo](https://github.com/fschaefer/Probability.js/raw/master/misc/Probability.js.png)\n\n# What is it?\n\nProbability.js makes it easy to call JavaScript functions by probability in\nNode.js and the browser.\n\n## Why?\n\nCircumstances are rare that you need to call functions by a certain probability\nin your daily work. But sometimes, especially in game development and in\nstatistical applications, it's very handy to have an easy way of doing so.\nThis library is inspired by [this](http://stackoverflow.com/questions/3983660/probability-in-javascript-help)\nquestion on stackoverflow.com.\n\n## Overview\n\n### Probabilitilized functions\n\nA `probabilitilized function` are several functions combined to one function by\n`probability objects`. It is created by calling the constructor `Probability()` \nwith `probability objects` as arguments:\n\n    var probabilitilized = new Probability(probabilityObject, probabilityObject /* , ... */);\n\nor with an array of `probability objects`:\n\n    var probabilitilized = new Probability([probabilityObject, probabilityObject /* , ... */]);\n\n### Probability objects\n\nA `probability object` consists of an object with the properties `p` and `f`.\n`p` is the probability by that the function `f` is called when the\n`probabilitilized function` is invoked.\n\nThe value of the probability `p` have to be a string with an integer value\nsuffixed with `%` between 0 and 100 or preferred a float lesser than or equal to\n1.0. `f` is an ordinary JavaScript function:\n\n    var probabilityObject = {\n        p: '50%',\n        f: function () {}\n    };\n    \n    /* or */\n    \n    var probabilityObject = {\n        p: 0.5,\n        f: function () {}\n    };\n\nThe sum of all probabilities `p` must be lesser or equal to `100%` or, respectively,\n`1.0`. Otherwise a `TypeError` is thrown. That's also the case for malformed\n`probabilityObjects`.\n\n## Usage example\n\n    /* a counter to show the number of function calls */\n    var counter = {\n        0: 0,\n        1: 0,\n        2: 0\n    };\n    \n    /* create a \"probabilitilized function\" by invoking Probability() with 3 \"probability objects\" */\n    var probabilitilized = new Probability({\n        p: '30%',                                         /* the probability by that ... */\n        f: function () {                                  /* ... this function is called */\n            counter[0]++;\n        }\n    }, {\n        p: '10%',\n        f: function () {\n            counter[1]++;\n        }\n    }, {\n        p: '60%',\n        f: function () {\n            counter[2]++;\n        }\n    });\n    \n    /* call the probabilitilized functions 100 times */\n    for (var i = 0; i \u003c 100; i++) {\n        probabilitilized();\n    }\n    \n    /* show that every function is called by its probability */\n    console.log(counter); // =\u003e {\"0\":27,\"1\":11,\"2\":62}\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffschaefer%2Fprobability.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffschaefer%2Fprobability.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffschaefer%2Fprobability.js/lists"}