# array-shuffle

> Randomize the order of items in an array

Latest version **4.1.0** (published 2026-02-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install array-shuffle
pnpm add array-shuffle
yarn add array-shuffle
bun add array-shuffle
```

## Health

**Score 60/100 (C)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2026-02-02 |
| First published | 2014-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 111 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | array, list, shuffle, sort, random, rand, fisher, yates, durstenfeld |

## Links

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

## Recent versions

- 4.1.0 (latest) — 2026-02-02
- 4.0.0 — 2025-09-19
- 3.0.0 — 2021-07-26
- 2.0.0 — 2020-12-03
- 1.0.1 — 2016-06-16
- 1.0.0 — 2014-08-13
- 0.1.0 — 2014-05-23

## README

# array-shuffle

> Randomize the order of items in an array

Uses the [Durstenfeld algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm) which is based on the [Fisher–Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle).

## Install

```sh
npm install array-shuffle
```

## Usage

```js
import {arrayToShuffled, arrayShuffle} from 'array-shuffle';

// Create a new shuffled array
const shuffled = arrayToShuffled([1, 2, 3, 4, 5, 6]);
//=> [3, 5, 4, 1, 2, 6]

// Shuffle in-place
const array = [1, 2, 3, 4, 5, 6];
arrayShuffle(array);
console.log(array);
//=> [3, 5, 4, 1, 2, 6]
```

## API

### arrayToShuffled(array, options?)

Create a new array with the items randomized (does not mutate the original array).

Returns a new array with the items randomized.

#### array

Type: `Array`

The array to shuffle.

#### options

Type: `object`

##### randomNumberGenerator

Type: `() => number`

Custom random number generator that returns a float between 0 (inclusive) and 1 (exclusive). This is useful for deterministic shuffling when you use a seeded generator.

```js
import {arrayToShuffled} from 'array-shuffle';

const randomNumberGenerator = () => 0;
const deterministic = arrayToShuffled([1, 2, 3, 4, 5, 6], {randomNumberGenerator});
//=> [2, 3, 4, 5, 6, 1]
```

### arrayShuffle(array, options?)

Randomize the order of items in an array, mutating the array in-place.

Returns the input array shuffled.

#### array

Type: `Array`

The array to shuffle.

#### options

Type: `object`

##### randomNumberGenerator

Type: `() => number`

Custom random number generator that returns a float between 0 (inclusive) and 1 (exclusive). This is useful for deterministic shuffling when you use a seeded generator.

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