{"id":13408061,"url":"https://github.com/sindresorhus/unique-random","last_synced_at":"2025-04-05T11:13:05.570Z","repository":{"id":11822663,"uuid":"14375190","full_name":"sindresorhus/unique-random","owner":"sindresorhus","description":"Generate random numbers that are consecutively unique","archived":false,"fork":false,"pushed_at":"2024-04-08T04:11:38.000Z","size":25,"stargazers_count":116,"open_issues_count":0,"forks_count":15,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-28T21:27:58.552Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/sindresorhus.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":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2013-11-13T20:14:20.000Z","updated_at":"2024-04-08T04:33:38.000Z","dependencies_parsed_at":"2022-07-15T14:47:45.954Z","dependency_job_id":"b46caf1c-78f6-429e-beb3-6580c1163351","html_url":"https://github.com/sindresorhus/unique-random","commit_stats":{"total_commits":28,"total_committers":4,"mean_commits":7.0,"dds":0.1785714285714286,"last_synced_commit":"cf69fbd6eea4090d85217a9ca71e73b6c454fa24"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Funique-random","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Funique-random/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Funique-random/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Funique-random/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/unique-random/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325696,"owners_count":20920714,"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-07-30T20:00:50.498Z","updated_at":"2025-04-05T11:13:05.548Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# unique-random\n\n\u003e Generate random numbers that are consecutively unique\n\nUseful for things like slideshows where you don't want to have the same slide twice in a row.\n\n## Install\n\n```sh\nnpm install unique-random\n```\n\n## Usage\n\n```js\nimport {consecutiveUniqueRandom} from 'unique-random';\n\nconst random = consecutiveUniqueRandom(1, 10);\n\nconsole.log(random(), random(), random());\n//=\u003e 5 2 6\n```\n\n## API\n\n### consecutiveUniqueRandom(minimum, maximum)\n\nGenerate random numbers that are consecutively unique, meaning that each number in the sequence is distinct from the one immediately before it.\n\n### exhaustiveUniqueRandom(minimum, maximum)\n\nGenerate random numbers that do not repeat until the entire range has appeared.\n\n### `consecutiveUniqueRandom` and `exhaustiveUniqueRandom`\n\nReturns a function, that when called, will return the generated number.\n\nThe returned function is also an iterable which consumes from the same source as the function:\n\n```js\nimport {exhaustiveUniqueRandom} from 'unique-random';\n\nconst random = exhaustiveUniqueRandom(1, 10);\n\nfor (const number of random) {\n\tconsole.log(number);\n\n\t// The unique numbers will be iterated over infinitely\n\tif (stopCondition) {\n\t\tbreak;\n\t}\n}\n```\n\n\u003e [!NOTE]\n\u003e If `minimum` is equal to `maximum`, the same value will always be returned.\n\n## Related\n\n- [unique-random-array](https://github.com/sindresorhus/unique-random-array) - Get consecutively unique elements from an array\n- [random-int](https://github.com/sindresorhus/random-int) - Generate a random integer\n- [random-float](https://github.com/sindresorhus/random-float) - Generate a random float\n- [random-item](https://github.com/sindresorhus/random-item) - Get a random item from an array\n- [random-obj-key](https://github.com/sindresorhus/random-obj-key) - Get a random key from an object\n- [random-obj-prop](https://github.com/sindresorhus/random-obj-prop) - Get a random property from an object\n- [unique-random-at-depth](https://github.com/Aweary/unique-random-at-depth) - This module with an optional depth argument\n- [crypto-random-string](https://github.com/sindresorhus/crypto-random-string) - Generate a cryptographically strong random string\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","Repository","包","目录","Number","JavaScript"],"sub_categories":["Number","数字","数量","Text"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Funique-random","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Funique-random","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Funique-random/lists"}