Gathering detailed insights and metrics for fast-shuffle
Gathering detailed insights and metrics for fast-shuffle
Gathering detailed insights and metrics for fast-shuffle
Gathering detailed insights and metrics for fast-shuffle
A fast, pure, side-effect-free, and deterministic implementation of Fisher-Yates Shuffle
npm install fast-shuffle
Typescript
Module System
Node Version
NPM Version
TypeScript (93.85%)
JavaScript (6.15%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
23 Stars
789 Commits
3 Forks
2 Watchers
7 Branches
3 Contributors
Updated on Jul 12, 2025
Latest Version
6.1.1
Package Id
fast-shuffle@6.1.1
Unpacked Size
9.26 kB
Size
3.87 kB
File Count
5
NPM Version
10.9.0
Node Version
22.10.0
Published on
Oct 28, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A fast, side-effect-free, and O(n) array shuffle that's safe for functional programming and use within Redux reducers.
npm install --save fast-shuffle
1import { shuffle } from 'fast-shuffle' 2 3const suits = ['♣', '♦', '♥', '♠'] 4const faces = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'] 5const sortedDeck = suits.map((suit) => faces.map((face) => face + suit)).flat() 6// [ '2♣', '3♣', '4♣', '5♣', '6♣', '7♣', '8♣', ... 7 8const shuffledDeck = shuffle(sortedDeck) 9// [ '3♥', '3♦', 'K♥', '6♦', 'J♣', '5♠', 'A♠', ...
The named shuffle
export seen above uses Math.random
for entropy. This is the easiest way to use the library, but it may be useful to create a purely functional shuffler which takes either a random seed which is used in a PCG for entropy, or a function (as seen here).
1import { createShuffle } from 'fast-shuffle' // note the change 2 3const letters = ['a', 'b', 'c', 'd', 'e'] 4const shuffleRed = createShuffle(12345) 5shuffleRed(letters) // [ 'a', 'b', 'c', 'd', 'e' ] 6shuffleRed(letters) // [ 'a', 'd', 'b', 'e', 'c' ] 7shuffleRed(letters) // [ 'c', 'a', 'e', 'b', 'd' ] 8shuffleRed(letters) // [ 'b', 'c', 'e', 'a', 'd' ] 9 10const shuffleBlue = createShuffle(12345) 11shuffleBlue(letters) // [ 'a', 'b', 'c', 'd', 'e' ] 12shuffleBlue(letters) // [ 'a', 'd', 'b', 'e', 'c' ] 13shuffleBlue(letters) // [ 'c', 'a', 'e', 'b', 'd' ] 14shuffleBlue(letters) // [ 'b', 'c', 'e', 'a', 'd' ]
The parameters are also curried, so it can be used in pipelines.
1import { createShuffle } from 'fast-shuffle' 2 3const randomCapitalLetter = 4 ['a', 'b', 'c', 'd', 'e', 'f'] // :: () -> [a] 5 |> createShuffle(Math.random), // :: [a] -> [a] 6 |> _ => _[0] // :: [a] -> a 7 |> _ => _.toUpperCase() // :: a -> a
If you give it an array of your source array and a random seed, you'll get a shuffled array and a new random seed back. This is a pure function and the original array is not mutated, so you can use it in your Redux reducers. The returned, shuffled array is a shallow copy, so if you use this in React, you will often avoid unnecessary rerenders.
1import { SHUFFLE_DECK } from './actions' 2import { createShuffle } from 'fast-shuffle' 3 4const initialState = { 5 ... 6 deck: ['♣', '♦', '♥', '♠'], 7 randomizer: Date.now() 8} 9 10const dealerApp = (state = initialState, action) => { 11 switch (action.type) { 12 ... 13 case SHUFFLE_DECK: 14 const [ deck, randomizer ] = createShuffle([state.deck, state.randomizer]) 15 return { 16 ...state, 17 deck, 18 randomizer, 19 } 20 ... 21 default: 22 return state 23 } 24}
It doesn't mutate your source array, so it's safe for Redux reducers.
The parameters are curried in the correct order, so you can use it within |>
or Ramda pipes.
You can make it a deterministic pure function, useful for shuffling in tests.
It's stupid-fast and scales to large arrays without breaking a sweat.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More