https://github.com/skepticalhippo/fisher-yates-shuffle
Fisher-Yates Shuffle Implementation in JavaScript
https://github.com/skepticalhippo/fisher-yates-shuffle
cards deck deck-building fisher javascript knuth random shuffle sort yates
Last synced: 24 days ago
JSON representation
Fisher-Yates Shuffle Implementation in JavaScript
- Host: GitHub
- URL: https://github.com/skepticalhippo/fisher-yates-shuffle
- Owner: SkepticalHippo
- Created: 2017-02-26T13:27:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-27T19:04:16.000Z (about 7 years ago)
- Last Synced: 2025-04-10T21:14:53.678Z (24 days ago)
- Topics: cards, deck, deck-building, fisher, javascript, knuth, random, shuffle, sort, yates
- Language: JavaScript
- Size: 6.84 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Fisher-Yates Shuffle [](https://travis-ci.org/SkepticalHippo/fisher-yates-shuffle)
A JavaScript implementation of the Fisher-Yates Shuffle algorithm.
## Requirements
* NodeJS 6+
## Installation
`npm install fisher-yates-shuffle --save`
## Usage
```js
const shuffle = require('fisher-yates-shuffle');
const deck = ['a', 'b', 'c', 'd'];
const shuffledDeck = shuffle(deck);
``````js
const randomizer = function() {
return 0.321
};
const shuffle = require('fisher-yates-shuffe');
const deck = ['a', 'b', 'c', 'd'];
const shuffledDeck = shuffle(deck, randomizer);
```## Notes
* It clones the given `Array`, so if it's rather large, make sure you have enough memory allocated.
* This library is still rather naïve and could be improved. If you have any suggestions, please open up an _Issue_ or a _Pull Request_.