Shuffles array elements in place.
This module implements the Fisher-Yates shuffle (a.k.a. the Knuth shuffle) to generate a random permutation of a finite set of
$ npm install compute-shuffle
For use in the browser, use browserify.
To use the module,
var shuffle = ;
shuffle( arr )
Mutates the input
array to generate a random permutation of
var shuffle = ;var data = 20 ;for var i = 0; i < datalength; i++data i = i;var copy;for var j = 0; j < 10; j++copy = data;;console;
To run the example code from the top-level application directory,
$ node ./examples/index.js
Beware of implementations on NPM and elsewhere which use bitwise operators to floor numeric values. When using bitwise operators, numeric values are converted to 32-bit integers. For large numeric values, you will experience unexpected results. While not a concern for this algorithm, bitwise operators also produce unexpected results when used on negative numeric values.
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a
./reports/coverage directory. To access an HTML version of the report,
$ make view-cov
Copyright © 2014. Athan Reines.