{"id":17437343,"url":"https://github.com/blixt/js-arbit","last_synced_at":"2025-12-30T06:36:29.234Z","repository":{"id":34302372,"uuid":"38212527","full_name":"blixt/js-arbit","owner":"blixt","description":"A tiny pseudo-random number generator.","archived":false,"fork":false,"pushed_at":"2015-06-29T18:37:53.000Z","size":103,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-24T06:55:39.266Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/arbit","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blixt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-28T20:09:22.000Z","updated_at":"2024-09-03T08:13:20.000Z","dependencies_parsed_at":"2022-09-14T06:11:10.662Z","dependency_job_id":null,"html_url":"https://github.com/blixt/js-arbit","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blixt%2Fjs-arbit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blixt%2Fjs-arbit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blixt%2Fjs-arbit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blixt%2Fjs-arbit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blixt","download_url":"https://codeload.github.com/blixt/js-arbit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241360978,"owners_count":19950372,"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":"2024-10-17T11:44:44.795Z","updated_at":"2025-12-30T06:36:29.167Z","avatar_url":"https://github.com/blixt.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"arbit\n=====\n\nA tiny pseudo-random number generator.\n\n\nExample\n-------\n\n```javascript\nvar arbit = require('arbit');\n\nvar random = arbit();\n\nvar HIT_CHANCE = 0.75;\nvar MIN_DAMAGE = 15, MAX_DAMAGE = 21;\n\nif (random() \u003c= HIT_CHANCE) {\n  var damage = random.nextInt(MIN_DAMAGE, MAX_DAMAGE + 1);\n  console.log('You hit the zombie for %d damage!', damage);\n} else {\n  console.log('You missed!');\n}\n```\n\n\nFunction reference\n------------------\n\n### `var generator = arbit(seed)`\n\nThe package itself is just a single function which returns a number\ngenerator using the provided seed. The seed can be any string.\n\n\n### `var generator = arbit.fromState(state)`\n\nReturns a number generator initialized to be in the provided state.\n\n\n### `var number = generator()`\n\nCalling the generator itself returns a value greater than or equal to\nzero, and less than one.\n\n\n### `var number = generator.nextFloat(max)`\n\nReturns a floating point that somewhere between zero and `max`. If a\nnegative number is provided, the range will instead be `(max, 0]`.\n\n\n### `var number = generator.nextFloat(min, max)`\n\nReturns a floating point number within either the range `[min, max)` or\n`(max, min]` (if the range is reversed).\n\n\n### `var number = generator.nextInt(max)`\n\nSame as `nextFloat(max)`, but coerces the value to an integer with\n`Math.floor`.\n\n\n### `var number = generator.nextInt(min, max)`\n\nSame as `nextFloat(min, max)`, but coerces the value to an integer with\n`Math.floor`.\n\n\n### `var state = generator.getState()`\n\nReturns the current state of the generator. This can be passed into\n`arbit.fromState(state)` to get back another generator in the same\nstate (i.e., it will generate the same sequence of numbers).\n\n\nWhy *arbit*?\n------------\n\n### Reproducibility\n\nThis library provides guaranteed reproducibility of observed sequences\nof numbers, given that you supply the same state to the PRNG. This is\nnot possible with `Math.random`.\n\n\n### Simplicity\n\n*arbit* is very small but provides additional functions for getting\nrandom ranges and integers.\n\n\n### Quality\n\n![Dilbert on randomness](http://i.imgur.com/Hn206vE.jpg)\n\nIt's very difficult to reason about what is random and what is not,\nespecially as a human being (we tend to see patterns where there are\nnone). Some important qualities to look for in a PRNG are:\n\n* No predictable/repeating patterns\n* Even distribution of numbers (no number is more likely than another)\n* Number of possible unique patterns that can be generated\n\n\n#### Verifying the quality\n\nIn this repo you will find the script `dieharder.bash`. Running it will\ngenerate a ~5 GB file sampling numbers from *arbit*, then pass it on to\n[Dieharder](http://www.phy.duke.edu/~rgb/General/dieharder.php) which\nwill test the quality of the output (how unpredictable it is).\n\nCompared to `Math.random`, *arbit* scores better in terms of randomness\nquality.\n\nBefore you can run the script, you need to install Dieharder. If you\nhave [Homebrew](http://brew.sh/) installed, doing so is easy:\n\n```bash\nbrew install dieharder\n```\n\nYou can now run the test:\n\n```bash\n./dieharder.bash\n```\n\nHave a look at [an example output][dieharder_arbit]. You can compare\nthis to [`Math.random`'s output][dieharder_math].\n\n\n### Performance\n\nThe goal of this library is to provide simple, good, reproducible, and\nperformant pseudo-random number generation. Here is a benchmark between\n`Math.random` and *arbit*, running on Node.js (v0.12.5):\n\n```\narbit x 55,539,526 ops/sec ±3.12% (93 runs sampled)\nMath.random x 62,497,530 ops/sec ±1.02% (93 runs sampled)\n```\n\n\n[dieharder_arbit]: https://gist.github.com/blixt/f4e52366d2b6517e94d6\n[dieharder_math]: https://gist.github.com/blixt/96667468b2b82f0f8396\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblixt%2Fjs-arbit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblixt%2Fjs-arbit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblixt%2Fjs-arbit/lists"}