# unique-random-array

> Get consecutively unique elements from an array

Latest version **4.0.0** (published 2024-05-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install unique-random-array
pnpm add unique-random-array
yarn add unique-random-array
bun add unique-random-array
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2024-05-18 |
| First published | 2015-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 76 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | unique, random, number, single, generate, non-repeating, array, item, element |

## Links

- npm: https://www.npmjs.com/package/unique-random-array
- Repository: https://github.com/sindresorhus/unique-random-array
- Homepage: https://github.com/sindresorhus/unique-random-array#readme
- Issues: https://github.com/sindresorhus/unique-random-array/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/unique-random-array

## Dependencies (1)

- [unique-random](https://npm.io/package/unique-random.md) ^4.0.0

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2024-05-18
- 3.0.0 — 2021-04-09
- 2.0.0 — 2019-04-12
- 1.0.1 — 2018-03-23
- 1.0.0 — 2015-01-19

## README

# unique-random-array

> Get consecutively unique elements from an array

Useful for things like slideshows where you don't want to have the same slide twice in a row.

## Install

```sh
npm install unique-random-array
```

## Usage

```js
import uniqueRandomArray from 'unique-random-array';

const random = uniqueRandomArray([1, 2, 3, 4]);

console.log(random(), random(), random(), random());
//=> 4 2 1 4
```

## API

### uniqueRandomArray(array)

Returns a function, that when called, will return a random element that's never the same as the previous, or `undefined` if the array is empty.

#### array

Type: `unknown[]`

## Related

- [unique-random](https://github.com/sindresorhus/unique-random) - Generate random numbers that are consecutively unique
- [random-int](https://github.com/sindresorhus/random-int) - Generate a random integer
- [random-float](https://github.com/sindresorhus/random-float) - Generate a random float
- [random-item](https://github.com/sindresorhus/random-item) - Get a random item from an array
- [random-obj-key](https://github.com/sindresorhus/random-obj-key) - Get a random key from an object
- [random-obj-prop](https://github.com/sindresorhus/random-obj-prop) - Get a random property from an object
- [crypto-random-string](https://github.com/sindresorhus/crypto-random-string) - Generate a cryptographically strong random string

---
_Source: https://npm.io/package/unique-random-array · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
