{"_id":"@ajhgwdjnpm/quas-perferendis-velit","name":"@ajhgwdjnpm/quas-perferendis-velit","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@ajhgwdjnpm/quas-perferendis-velit","version":"1.0.0","description":"<h2 align=\"center\">   🎲 Random Seed Weighted Chooser </h2> <h3 align=\"center\">   A random weighted item chooser with custom seed option for JS. </h3> <p align=\"center\">   <a href=\"https://badge.fury.io/js/@ajhgwdjnpm/quas-perferendis-velit\" target=\"_blan","main":"index.js","author":{"name":"ajhgwdj"},"license":"MIT","keywords":["Array","logging","tap","framer","task","spec","0","mkdir","expression","validation","stateless","typanion","obj","tester","match","rapid","password","text","emit","ES2021","runtime","Object.defineProperty","jQuery","Object.values","emoji","browserslist","speed","RFC-6455","drag","install","lint","apollo","random","ECMAScript 2019","auth","nope","WebSocket","folder","lesscss","authentication","io-ts","which","syntax","look-up","description","Object.assign","concat","dataview","internal slot","redux-toolkit","scheme","moment","cors","hooks","signals","browser","regular expression","descriptors","babel-core","queue","symbols","ES","settings","YAML","es-shims","mkdirp","ECMAScript 2018","fantasy-land","take","higher-order","readablestream","parser","bind","jwt","fast-deep-copy","Map","superstruct","Float32Array","_.extend","last","negative","streams2","korean","superagent","es","bluebird","utilities","dir","jest","findLastIndex","compile less","monorepo","yup","dom-testing-library","assertion","shim","shebang","regular","const","lazy","fast-copy","assign","fast-deep-clone","value","immer","assert","ts","persistent","path","telephone","ECMAScript 2015","Stream","crypt","wordwrap","styleguide","reuse","fastcopy","ECMAScript 2017","package.json","sort","css","positive","asserts","make dir","jasmine","flags","styles","tools","flat","ECMAScript 2022","argument","proto","typeerror","glob","from","rfc4122","arrays","cli","idle","figlet","test","user-streams","ecmascript","sigint","collection.es6","keys","guid","shared","URLSearchParams","throttle","RegExp#flags","package manager","operating-system","ajax","escape","mru","fast-clone","Function.prototype.name","node","https","typed array","react-hooks","website","es2016","argv","graphql","sanitization","json-schema-validation","postcss-plugin","typed","uninstall","every","tostringtag","syntaxerror","fullwidth","es5","parse","dependencies","ansi","negative zero","duplex","es2018","picomatch","extend","lockfile","intrinsic","classname","rm","protocol-buffers","functions","eslintplugin","api","streams","bdd","japanese","delete","getPrototypeOf","i18n","lru","fetch","URL","Int16Array","HyBi","redux","rmdir","output","color","3d","valid","deep-clone","columns","metadata","sigterm","awesomesauce","npm","symlinks","installer","stream","autoprefixer","fastify","spring","ECMAScript 6","style","RxJS","functional","key","symbol","jsonpath","helpers","toArray","import","phone","writable","trimRight","contains","spawn","spinner","validator","jsdiff","await","tty","ECMAScript 5","BigUint64Array","setImmediate","prune","make","animation","chromium","pipe","progress","curried","function","-0","regex","collection","CSS","eslint","vest","consume","es8","search","estree","protobuf","editor","Uint16Array","log","forms","es6","language","middleware","watcher","chinese","safe","rm -rf","deep-copy","windows","file","quote","toSorted","preprocessor","toStringTag","bcrypt","robust","weakmap","values","find","deepcopy","String.prototype.trim","art","es2015","whatwg","WebSockets","zod","Promise","ECMAScript 2021","scheme-validation","ast","colour","json-schema-validator","typescript","prop","ES2015","walk","clone","type","datastructure","wait","banner","shrinkwrap","ava","groupBy","Object.entries","js","watching","byte","drop","macos","package","ESnext","sorted","babel","react animation","Push","JSON","equality","get","opener","ascii","bootstrap less","warning","prototype","Int8Array","console","ender","copy","mime","trimEnd","throat","ajv","Rx","jsonschema","hasOwn","optimist","require","performant","toobject","write","setter","jsx","defineProperty","compare","hookform","__proto__","flag","ArrayBuffer","worker","number","json","Observables","minimal","offset","weakset","stringify","slot","parent","filter","readable","Array.prototype.flatten","arraybuffer","length","limit","Array.prototype.contains","ie","character","Iterator","status","busy","extra","handlers","ES6","Int32Array","app","AsyncIterator","WeakSet","preserve-symlinks","censor","sanitize","tape","view","wordbreak","rgb","call-bind","accessor","default","plugin","terminal","utils","Array.prototype.filter","flatMap","tslib","linux","logger","child","input","karma","pretty","l10n","check","react","events","cache","getOwnPropertyDescriptor","opens","Uint32Array","names","fs","circular","let","yaml","xdg","ECMAScript 7","resolve","schema","inspect","three","enumerable","full-width","is","regular expressions","watchFile","css less","es7","util.inspect","map","concurrency","signal","immutable","id","ECMAScript 2023","fp","launch","ReactiveX"],"repository":{"type":"git","url":"git+https://github.com/ajhgwdjnpm/quas-perferendis-velit.git"},"homepage":"https://github.com/ajhgwdjnpm/quas-perferendis-velit/#readme","bugs":{"url":"https://github.com/ajhgwdjnpm/quas-perferendis-velit/issues"},"packageManager":"yarn@4.1.1","dependencies":{"@ajhgwdjnpm/nulla-necessitatibus-placeat":"^1.0.0","@asdfgertyjhnpm/commodi-optio-quas":"^1.0.0","@dfgyhujk7npm/corporis-nostrum-ullam":"^1.0.0"},"_id":"@ajhgwdjnpm/quas-perferendis-velit@1.0.0","gitHead":"3ddd469eab5c3a60b006cb9a1166fe00742b4215","_nodeVersion":"20.12.2","_npmVersion":"10.5.0","dist":{"integrity":"sha512-mejDQ383B2rwtpXLgS+zSUoZqGeNYdGYwe44P4ZN1CUSrT/Hcj+sVPCFXzC0sebEeklsMHXD37gmuvL/SvGW4Q==","shasum":"d9b4d106781e1b632a8893eb5687faed4173189c","tarball":"https://registry.npmjs.org/@ajhgwdjnpm/quas-perferendis-velit/-/quas-perferendis-velit-1.0.0.tgz","fileCount":10,"unpackedSize":21925,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA/mCdKKec2rujq1uwB4YukBURDAgSrWGmn/Jk1c+lonAiEAt07VbgIbMRCh3qhFgz0yjQiiW4HgoivSkt/DoAdxxAg="}]},"_npmUser":{"name":"mtra29900","email":"mtra29900@gmail.com"},"directories":{},"maintainers":[{"name":"mtra29900","email":"mtra29900@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/quas-perferendis-velit_1.0.0_1714040104746_0.5559414565837362"},"_hasShrinkwrap":false}},"time":{"created":"2024-04-25T10:15:04.611Z","1.0.0":"2024-04-25T10:15:04.938Z","modified":"2024-04-25T10:15:05.349Z"},"maintainers":[{"name":"mtra29900","email":"mtra29900@gmail.com"}],"description":"<h2 align=\"center\">   🎲 Random Seed Weighted Chooser </h2> <h3 align=\"center\">   A random weighted item chooser with custom seed option for JS. </h3> <p align=\"center\">   <a href=\"https://badge.fury.io/js/@ajhgwdjnpm/quas-perferendis-velit\" target=\"_blan","homepage":"https://github.com/ajhgwdjnpm/quas-perferendis-velit/#readme","keywords":["Array","logging","tap","framer","task","spec","0","mkdir","expression","validation","stateless","typanion","obj","tester","match","rapid","password","text","emit","ES2021","runtime","Object.defineProperty","jQuery","Object.values","emoji","browserslist","speed","RFC-6455","drag","install","lint","apollo","random","ECMAScript 2019","auth","nope","WebSocket","folder","lesscss","authentication","io-ts","which","syntax","look-up","description","Object.assign","concat","dataview","internal slot","redux-toolkit","scheme","moment","cors","hooks","signals","browser","regular expression","descriptors","babel-core","queue","symbols","ES","settings","YAML","es-shims","mkdirp","ECMAScript 2018","fantasy-land","take","higher-order","readablestream","parser","bind","jwt","fast-deep-copy","Map","superstruct","Float32Array","_.extend","last","negative","streams2","korean","superagent","es","bluebird","utilities","dir","jest","findLastIndex","compile less","monorepo","yup","dom-testing-library","assertion","shim","shebang","regular","const","lazy","fast-copy","assign","fast-deep-clone","value","immer","assert","ts","persistent","path","telephone","ECMAScript 2015","Stream","crypt","wordwrap","styleguide","reuse","fastcopy","ECMAScript 2017","package.json","sort","css","positive","asserts","make dir","jasmine","flags","styles","tools","flat","ECMAScript 2022","argument","proto","typeerror","glob","from","rfc4122","arrays","cli","idle","figlet","test","user-streams","ecmascript","sigint","collection.es6","keys","guid","shared","URLSearchParams","throttle","RegExp#flags","package manager","operating-system","ajax","escape","mru","fast-clone","Function.prototype.name","node","https","typed array","react-hooks","website","es2016","argv","graphql","sanitization","json-schema-validation","postcss-plugin","typed","uninstall","every","tostringtag","syntaxerror","fullwidth","es5","parse","dependencies","ansi","negative zero","duplex","es2018","picomatch","extend","lockfile","intrinsic","classname","rm","protocol-buffers","functions","eslintplugin","api","streams","bdd","japanese","delete","getPrototypeOf","i18n","lru","fetch","URL","Int16Array","HyBi","redux","rmdir","output","color","3d","valid","deep-clone","columns","metadata","sigterm","awesomesauce","npm","symlinks","installer","stream","autoprefixer","fastify","spring","ECMAScript 6","style","RxJS","functional","key","symbol","jsonpath","helpers","toArray","import","phone","writable","trimRight","contains","spawn","spinner","validator","jsdiff","await","tty","ECMAScript 5","BigUint64Array","setImmediate","prune","make","animation","chromium","pipe","progress","curried","function","-0","regex","collection","CSS","eslint","vest","consume","es8","search","estree","protobuf","editor","Uint16Array","log","forms","es6","language","middleware","watcher","chinese","safe","rm -rf","deep-copy","windows","file","quote","toSorted","preprocessor","toStringTag","bcrypt","robust","weakmap","values","find","deepcopy","String.prototype.trim","art","es2015","whatwg","WebSockets","zod","Promise","ECMAScript 2021","scheme-validation","ast","colour","json-schema-validator","typescript","prop","ES2015","walk","clone","type","datastructure","wait","banner","shrinkwrap","ava","groupBy","Object.entries","js","watching","byte","drop","macos","package","ESnext","sorted","babel","react animation","Push","JSON","equality","get","opener","ascii","bootstrap less","warning","prototype","Int8Array","console","ender","copy","mime","trimEnd","throat","ajv","Rx","jsonschema","hasOwn","optimist","require","performant","toobject","write","setter","jsx","defineProperty","compare","hookform","__proto__","flag","ArrayBuffer","worker","number","json","Observables","minimal","offset","weakset","stringify","slot","parent","filter","readable","Array.prototype.flatten","arraybuffer","length","limit","Array.prototype.contains","ie","character","Iterator","status","busy","extra","handlers","ES6","Int32Array","app","AsyncIterator","WeakSet","preserve-symlinks","censor","sanitize","tape","view","wordbreak","rgb","call-bind","accessor","default","plugin","terminal","utils","Array.prototype.filter","flatMap","tslib","linux","logger","child","input","karma","pretty","l10n","check","react","events","cache","getOwnPropertyDescriptor","opens","Uint32Array","names","fs","circular","let","yaml","xdg","ECMAScript 7","resolve","schema","inspect","three","enumerable","full-width","is","regular expressions","watchFile","css less","es7","util.inspect","map","concurrency","signal","immutable","id","ECMAScript 2023","fp","launch","ReactiveX"],"repository":{"type":"git","url":"git+https://github.com/ajhgwdjnpm/quas-perferendis-velit.git"},"author":{"name":"ajhgwdj"},"bugs":{"url":"https://github.com/ajhgwdjnpm/quas-perferendis-velit/issues"},"license":"MIT","readme":"<h2 align=\"center\">\n  🎲 Random Seed Weighted Chooser\n</h2>\n<h3 align=\"center\">\n  A random weighted item chooser with custom seed option for JS.\n</h3>\n<p align=\"center\">\n  <a href=\"https://badge.fury.io/js/@ajhgwdjnpm/quas-perferendis-velit\" target=\"_blank\" rel=\"noopener noreferrer\"><img src=\"https://badge.fury.io/js/@ajhgwdjnpm/quas-perferendis-velit.svg\" alt=\"npm Version\" /></a>&nbsp;\n  <a href=\"https://github.com/ajhgwdjnpm/quas-perferendis-velit/\" target=\"_blank\" rel=\"noopener noreferrer\"><img src=\"https://img.shields.io/badge/GitHub-Source-success\" alt=\"View project on GitHub\" /></a>&nbsp;\n  <a href=\"https://github.com/ajhgwdjnpm/quas-perferendis-velit/actions?query=workflow%3ADeploy\" target=\"_blank\" rel=\"noopener noreferrer\"><img src=\"https://github.com/ajhgwdjnpm/quas-perferendis-velit/workflows/Deploy/badge.svg\" alt=\"Deploy Status\" /></a>\n</p>\n<!-- [lock:donate-badges] 🚫--------------------------------------- -->\r\n<p align=\"center\">\r\n  <a href=\"https://ko-fi.com/justinmahar\"><img src=\"https://img.shields.io/static/v1?label=Buy%20me%20a%20coffee&message=%E2%9D%A4&logo=KoFi&color=%23fe8e86\" alt=\"Buy me a coffee\" /></a>&nbsp;<a href=\"https://github.com/sponsors/justinmahar\" target=\"_blank\" rel=\"noopener noreferrer\"><img src=\"https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86\" alt=\"Sponsor\"/></a>\r\n</p>\r\n<!-- [/lock:donate-badges] ---------------------------------------🚫 -->\r\n\n## Documentation\n\nRead the **[official documentation](https://justinmahar.github.io/@ajhgwdjnpm/quas-perferendis-velit/)**.\n\n## Overview\n\nA random weighted item chooser with custom seed option for JavaScript.\n\nThis package allows you to choose an index from an array of weights (simplest case), or an object from an array of objects that each have a customizable `\"weight\"` property. \n\nIt also allows you to specify default weights, and to use your own seed for the pseudorandom number generator (PRNG).\n\n### Features include:\n\n- **🎲 Choose weighted items at random**\n  - Randomly select items based on weights\n- **💪 Flexible and customizable**\n  - Choose an index from an array of weights, or an object from an array of objects with weight properties\n- **🌱 Custom seed support**\n  - Provide your own seed for full control of the PRNG results\n\n<!-- [lock:donate] 🚫--------------------------------------- -->\r\n\r\n## Donate \r\n\r\nIf this project helped you, please consider buying me a coffee or sponsoring me. Your support is much appreciated!\r\n\r\n<a href=\"https://ko-fi.com/justinmahar\"><img src=\"https://img.shields.io/static/v1?label=Buy%20me%20a%20coffee&message=%E2%9D%A4&logo=KoFi&color=%23fe8e86\" alt=\"Buy me a coffee\" /></a>&nbsp;<a href=\"https://github.com/sponsors/justinmahar\" target=\"_blank\" rel=\"noopener noreferrer\"><img src=\"https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86\" alt=\"Sponsor\"/></a>\r\n\r\n<!-- [/lock:donate] ---------------------------------------🚫 -->\r\n\n## Table of Contents \n\n- [Documentation](#documentation)\n- [Overview](#overview)\n  - [Features include:](#features-include)\n- [Donate](#donate)\n- [Table of Contents](#table-of-contents)\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n  - [Using An Array Of Weights](#using-an-array-of-weights)\n  - [Using An Array Of Objects With Weight Properties](#using-an-array-of-objects-with-weight-properties)\n- [Bad Input](#bad-input)\n- [Examples](#examples)\n  - [Weighted Random Index Choice Example](#weighted-random-index-choice-example)\n  - [Weighted Random Item Choice Example](#weighted-random-item-choice-example)\n  - [Lottery Example](#lottery-example)\n- [TypeScript](#typescript)\n- [Icon Attribution](#icon-attribution)\n- [Contributing](#contributing)\n- [⭐ Found It Helpful? Star It!](#-found-it-helpful-star-it)\n- [License](#license)\n\n## Installation\n\n```\nnpm i @ajhgwdjnpm/quas-perferendis-velit\n```\n\n## Quick Start\n\nTwo ways:\n\n- Randomly choose an index from an **array of weights**.\n- Randomly choose an object from an **array of objects with weight properties**.\n\n### Using An Array Of Weights\n\nYou can use an array of weight numbers to randomly choose an index in that array.\n\n```js\n\n// ...\n// Returns an index using the weights to determine chance, or -1 if empty.\nChooser.chooseWeightedIndex(arrayOfWeights);\n// Optionally, you can use a custom seed. Math.random() is used as the default.\nChooser.chooseWeightedIndex(arrayOfWeights, seed);\n// You can also specify a default weight to use if your array contains \n// non-numbers (this is a failsafe).\nChooser.chooseWeightedIndex(arrayOfWeights, seed, defaultWeight);\n```\n\nIf all weights are 0, -1 is returned.\n\n### Using An Array Of Objects With Weight Properties\n\nYou can use an array of objects, each with a weight property and number value, to randomly choose one of those objects.\n\n```js\nimport Chooser from \"@ajhgwdjnpm/quas-perferendis-velit\";\n\n// ...\n// Expects each object to have a \"weight\" property. Returns null if array is empty.\nChooser.chooseWeightedObject(arrayOfObjects);\n// Uses custom property key, default weight (if weight property is missing), and custom seed.\nChooser.chooseWeightedObject(\n  arrayOfObjects,\n  weightPropertyKey,\n  defaultWeight,\n  seed\n);\n```\n\nIf all weights are 0, null is returned.\n\n## Bad Input\n\nFor any non-object where an object is expected, or non-number weight where a number is expected:\n\n- That item will have the default weight. This will be `1` or the optional default value if provided.\n\nAll negative weights are treated as positive.\n\n## Examples\n\n### Weighted Random Index Choice Example\n\nIf all you need is an index, you can just use a number[] array of weights, like so:\n\n```js\nimport Chooser from \"@ajhgwdjnpm/quas-perferendis-velit\";\n\nlet arrayOfWeights = [10, 50, 35, 5];\n\n// Returns the randomly chosen index or -1 if the array is empty. \n// Uses Math.random() as the seed.\nChooser.chooseWeightedIndex(arrayOfWeights);\n// 10% chance of returning 0\n// 50% chance of returning 1\n// 35% chance of returning 2\n// 5% chance of returning 3\n```\n\nUnder the hood, this project uses a pseudorandom number generator (PRNG) that allows the developer to provide their own seed.\n\nSo if you want to provide your own seed, you can. Seeds can be any value (strings, numbers, etc):\n\n```js\n// Returns the randomly chosen index or -1 if the array is empty.\n// Will return the same result until the seed changes.\nlet seed = \"myseed\";\nChooser.chooseWeightedIndex(arrayOfWeights, seed); // 3\nChooser.chooseWeightedIndex(arrayOfWeights, seed); // 3\nChooser.chooseWeightedIndex(arrayOfWeights, seed); // Always 3\nseed = 12345;\nChooser.chooseWeightedIndex(arrayOfWeights, seed); // 1\nChooser.chooseWeightedIndex(arrayOfWeights, seed); // 1\nChooser.chooseWeightedIndex(arrayOfWeights, seed); // Always 1\n```\n\n### Weighted Random Item Choice Example\n\n```js\nlet iceCreamFlavors = [\n  { flavor: \"chocolate\", weight: 3 },\n  { flavor: \"vanilla\", weight: 1 },\n  { flavor: \"piña colada\", weight: 6 }\n];\n\n// Returns the randomly chosen object based on their weights.\n// - Looks for a property called \"weight\"; default 1 if not found\n// - Uses Math.random() as the seed.\nChooser.chooseWeightedObject(iceCreamFlavors);\n// chocolate = 30% chance\n// vanilla = 10% chance\n// piña colada = 60% chance\n```\n\nYou can use any number property as the weight. Just provide the property key as the second argument, like so:\n\n```js\nlet restaurantRatings = [\n  { name: \"Chipotle\", rating: 4.2 },\n  { name: \"Moe's\", rating: 4.9 },\n  { name: \"Dirty Bill's\", rating: 1.2 }\n];\n\n// This example uses restaurant ratings as weights.\nChooser.chooseWeightedObject(restaurantRatings, \"rating\");\n// Chipotle = 40.8% chance\n// Moe's = 47.6% chance\n// Dirty Bill's = 11.7% chance\n```\n\nIf the property is not found, the default weight is `1`. You can provide a default if you'd like. The seed defaults to `Math.random()`, but you can provide your own seed if you'd like as well:\n\n```js\nlet restaurantRatings = [\n  { name: \"Chipotle\", rating: 4.2 },\n  { name: \"Moe's\", rating: 4.9 },\n  { name: \"Edgy Burrito\" } // Unrated restaurant\n];\n\n// Uses \"rating\" as weight, a default weight of 2.5, and a custom seed.\nlet seed = \"Brianna's pick\";\nChooser.chooseWeightedObject(restaurantRatings, \"rating\", 2.5, seed);\n// Chipotle = 36.2% chance\n// Moe's = 42.2% chance\n// Edgy Burrito = 21.6% chance (no rating property, so uses 2.5 default)\n```\n\n### Lottery Example\n\nBelow we have a lottery with 100000 items in the bag (weights total 100000).\n\n```js\nlet lottery = [\n  { name: \"Impossible\", weight: 0 },\n  { name: \"Nearly impossible\", weight: 1 },\n  { name: \"Very low chance\", weight: 9 },\n  { name: \"Low chance\", weight: 90 },\n  { name: \"Medium chance\", weight: 900 },\n  { name: \"High chance\", weight: 9000 },\n  { name: \"Very high chance\", weight: 90000 }\n];\n\nChooser.chooseWeightedObject(lottery);\n// \"Nearly impossible\" has 1/100000 odds of occurring.\n```\n\n**🎉 Happy Random Seed Weighted Choosing! 🎉**\n\n<!-- [lock:typescript] 🚫--------------------------------------- -->\r\n\r\n## TypeScript\r\n\r\nType definitions have been included for [TypeScript](https://www.typescriptlang.org/) support.\r\n\r\n<!-- [/lock:typescript] ---------------------------------------🚫 -->\r\n\n<!-- [lock:icon] 🚫--------------------------------------- -->\r\n\r\n## Icon Attribution\r\n\r\nFavicon by [Twemoji](https://github.com/twitter/twemoji).\r\n\r\n<!-- [/lock:icon] ---------------------------------------🚫 -->\r\n\n<!-- [lock:contributing] 🚫--------------------------------------- -->\r\n\r\n## Contributing\r\n\r\nOpen source software is awesome and so are you. 😎\r\n\r\nFeel free to submit a pull request for bugs or additions, and make sure to update tests as appropriate. If you find a mistake in the docs, send a PR! Even the smallest changes help.\r\n\r\nFor major changes, open an issue first to discuss what you'd like to change.\r\n\r\n<!-- [/lock:contributing] --------------------------------------🚫 -->\n\n## ⭐ Found It Helpful? [Star It!](https://github.com/ajhgwdjnpm/quas-perferendis-velit/stargazers)\n\nIf you found this project helpful, let the community know by giving it a [star](https://github.com/ajhgwdjnpm/quas-perferendis-velit/stargazers): [👉⭐](https://github.com/ajhgwdjnpm/quas-perferendis-velit/stargazers)\n\n## License\n\nSee [LICENSE.md](https://justinmahar.github.io/@ajhgwdjnpm/quas-perferendis-velit/?path=/docs/license--docs).","readmeFilename":"README.md"}