MCPcopy Create free account
hub / github.com/cryptii/cryptii / shuffle

Method shuffle

src/ArrayUtil.js:102–111  ·  view source on GitHub ↗

* Orders array elements randomly using Fisher–Yates modern shuffle algorithm. * @param {array} array * @param {Random} [random] Random instance * @return {array} Shuffled array

(array, random = null)

Source from the content-addressed store, hash-verified

100 * @return {array} Shuffled array
101 */
102 static shuffle (array, random = null) {
103 random = random || Random.getInstance()
104 const a = array.slice()
105 let i, j
106 for (i = a.length - 1; i > 0; i--) {
107 j = random.nextInteger(0, i)
108 ;[a[i], a[j]] = [a[j], a[i]]
109 }
110 return a
111 }
112
113 /**
114 * Chunks the given array into slices of equal length.

Callers 4

randomizeMethod · 0.80
randomizeValueMethod · 0.80

Calls 2

nextIntegerMethod · 0.80
getInstanceMethod · 0.45

Tested by

no test coverage detected