crypto-secure-shuffle
TypeScript icon, indicating that this package has built-in type declarations

2.0.5 • Public • Published

Crypto Secure Shuffle

Build Status Coverage Status Known Vulnerabilities

Cryptographically secure shuffle using the Durstenfeld algorithm with a CSPRNG.

This provides an unbiased algorithm for producing random permutations of a given array.

Install

$ npm install crypto-secure-shuffle

Usage

Note the original array is mutated, as it is shuffled in place for efficiency. Also note that this method is asynchronous. For convenience the returned promise resolves to the shuffled array.

const shuffle = require("crypto-secure-shuffle");
 
const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
 
// shuffles the array in-place
await shuffle(arr);
 
// e.g., [ 7, 3, 5, 0, 6, 9, 4, 2, 1, 8 ]
console.log(arr);

License

ISC

Package Sidebar

Install

npm i crypto-secure-shuffle

Weekly Downloads

4

Version

2.0.5

License

ISC

Unpacked Size

12.4 kB

Total Files

12

Last publish

Collaborators

  • dhessler