@itreg/shuffle-array 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itreg/shuffle-array",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A small library that takes an array as input and returns a new array that is shuffled.",
5
5
  "main": "dist/index.js",
6
6
  "umd:main": "dist/index.umd.js",
package/src/index.js CHANGED
@@ -4,3 +4,12 @@ export default function shuffleArray(array) {
4
4
  .sort((currentItem, nextItem) => currentItem.sort - nextItem.sort)
5
5
  .map(({ value }) => value);
6
6
  };
7
+
8
+ // Cryptographic shuffle using cryptoRandom()
9
+ const crypto = require('crypto');
10
+ export function cryptoShuffleArray(array) {
11
+ return array
12
+ .map(value => ({ value, sort: crypto.randomInt(0, 2 ** 32) }))
13
+ .sort((a, b) => a.sort - b.sort)
14
+ .map(({ value }) => value);
15
+ };