Generate random numbers that are consecutively unique or exhaustively unique within a range.
Unique-random is a JavaScript library that generates random numbers with specific uniqueness constraints. It solves the problem of needing random sequences where values don't repeat consecutively or until all possibilities are exhausted, which is useful for slideshows, games, or any application where immediate repeats are undesirable.
JavaScript developers building applications that require controlled random sequences, such as slideshow presentations, game mechanics, or data sampling tools.
Developers choose unique-random for its simple API, clear uniqueness guarantees, and iterable interface, which provide more control over random number generation than standard Math.random() without complex manual implementations.
Generate random numbers that are consecutively unique
Functions like consecutiveUniqueRandom(min, max) require only two parameters, making integration straightforward, as shown in the basic usage example.
The returned random function is also an iterable, allowing direct use in for...of loops for infinite sequences, demonstrated in the README's iteration example.
Offers two specific modes—consecutive and exhaustive—that prevent back-to-back repeats or ensure full range coverage, ideal for slideshows and games mentioned in the description.
Part of a family of sindresorhus utilities, with related projects like unique-random-array for array-based randomness, enhancing utility for developers.
Lacks the ability to seed the random number generator, making it unsuitable for deterministic testing or scenarios requiring reproducible sequences.
Restricted to integer generation within min/max bounds; for floating-point numbers, developers must use separate libraries like random-float, as indicated in related projects.
In exhaustiveUniqueRandom mode, tracking used numbers to ensure no repeats until exhaustion can be memory-intensive for large ranges, a trade-off for the uniqueness guarantee.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.