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

Method randomizeValue

src/Field/Text.js:268–290  ·  view source on GitHub ↗

* Returns a randomly chosen value or null if not applicable. * @param {Random} random Random number generator * @return {mixed} Randomly chosen value

(random)

Source from the content-addressed store, hash-verified

266 * @return {mixed} Randomly chosen value
267 */
268 randomizeValue (random) {
269 const value = super.randomizeValue(random)
270 if (value !== null) {
271 return value
272 }
273 if (this.isValid()) {
274 if (this.isUniqueChars()) {
275 // Shuffle the characters of the current value
276 const codePoints = this.getValue().getCodePoints()
277 return Chain.wrap(ArrayUtil.shuffle(codePoints, random))
278 } else if (this.getWhitelistChars() !== null) {
279 // Use the current value's length to
280 // produce the same amount of random chars
281 const length = this.getValue().getLength()
282 const codePoints = []
283 for (let i = 0; i < length; i++) {
284 codePoints.push(random.nextChoice(this.getWhitelistChars()))
285 }
286 return Chain.wrap(codePoints)
287 }
288 }
289 return null
290 }
291
292 /**
293 * Serializes the value to a JSON serializable object.

Callers

nothing calls this directly

Calls 9

isUniqueCharsMethod · 0.95
getWhitelistCharsMethod · 0.95
getCodePointsMethod · 0.80
wrapMethod · 0.80
shuffleMethod · 0.80
nextChoiceMethod · 0.80
isValidMethod · 0.45
getValueMethod · 0.45
getLengthMethod · 0.45

Tested by

no test coverage detected