{"id":16125570,"url":"https://github.com/semibran/prnguin","last_synced_at":"2025-03-18T13:30:49.078Z","repository":{"id":57241436,"uuid":"80168386","full_name":"semibran/prnguin","owner":"semibran","description":":penguin: deterministic pseudorandom number generation","archived":false,"fork":false,"pushed_at":"2018-04-25T17:12:00.000Z","size":20,"stargazers_count":12,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T20:35:31.212Z","etag":null,"topics":["math","prng","probability","random","rng"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/prnguin","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/semibran.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-27T00:14:25.000Z","updated_at":"2024-03-24T10:44:39.000Z","dependencies_parsed_at":"2022-09-07T23:13:21.531Z","dependency_job_id":null,"html_url":"https://github.com/semibran/prnguin","commit_stats":null,"previous_names":["semibran/random"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Fprnguin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Fprnguin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Fprnguin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Fprnguin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/semibran","download_url":"https://codeload.github.com/semibran/prnguin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244231469,"owners_count":20419957,"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":["math","prng","probability","random","rng"],"created_at":"2024-10-09T21:30:00.986Z","updated_at":"2025-03-18T13:30:47.163Z","avatar_url":"https://github.com/semibran.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prnguin\nThis module contains a small collection of simple \"generators\", i.e. pure functions that transform a number into a predictable output value. You will usually want to change the seed after every use (typically by incrementing it) unless your goal is to get the same results multiple times.\n\nSince generators are just functions, crafting your own custom generators to match specific scenarios is a trivial matter. For example, the following generator simulates the rolling of a six-sided die.\n```js\nfunction roll(seed) {\n  return integer(1, 6, seed)\n}\n```\nAdditionally, all the functions in this module derive their seemingly random nature from `percent`, further demonstrating their composability.\n\n## usage\n[![NPM](https://nodei.co/npm/prnguin.png?mini)](https://www.npmjs.com/package/prnguin)\n```js\nconst { percent, integer, boolean, pick, shuffle } = require(\"prnguin\")\n```\n\n### `percent(seed)`\nGenerate a number between `0` and `1` using `seed`, **exclusively**.\n```js\nif (percent(seed++) \u003c 0.1) {\n  money.type = \"gold\"\n} else {\n  money.type = \"copper\"\n}\n```\n`1` **is not** included in the set of possible return values, so this function is essentially a seedable version of `Math.random()`.\n\n### `integer(min, max, seed)`\nGenerate an integer between `min` and `max` using `seed`, **inclusively**.\n```js\n\u003e integer(1, 10, seed++)\n6\n```\nUnlike `percent`, the upper number (`max`) is included in the set of possible return values.\n\n### `boolean(seed)`\nChoose either `true` and `false` based on the given `seed`.\n```js\nif (boolean(seed++)) {\n  for (let connector of connectors) {\n    floors.push(connector)\n  }\n} else {\n  let connector = pick(connectors, seed++)\n  doors.push(connector)\n}\n```\n\n### `pick(array, seed)`\nChooses a random element from `array` using `seed`.\n```js\nlet card = pick(deck, seed++)\n```\n\n### `shuffle(array, seed)`\nShuffles the items in `array` in place using `seed`.\n```js\nshuffle(deck, seed++)\n```\n\n## license\n[MIT](https://opensource.org/licenses/MIT) © [Brandon Semilla](https://git.io/semibran)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemibran%2Fprnguin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsemibran%2Fprnguin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemibran%2Fprnguin/lists"}