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

Method randomizeValue

src/Field/Byte.js:117–134  ·  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

115 * @return {mixed} Randomly chosen value
116 */
117 randomizeValue (random) {
118 const value = super.randomizeValue(random)
119 if (value !== null) {
120 return value
121 }
122 if (this._randomizeSize !== null) {
123 // Use randomize size
124 return random.nextBytes(this._randomizeSize)
125 } else if (this.getMinSize() !== null) {
126 // Use the min size
127 return random.nextBytes(this.getMinSize())
128 } else if (this.isValid()) {
129 // Use the current value's size to
130 // produce the same amount of random bytes
131 return random.nextBytes(this.getValue().length)
132 }
133 return null
134 }
135
136 /**
137 * Serializes the field value to a JSON serializable value.

Callers

nothing calls this directly

Calls 4

getMinSizeMethod · 0.95
nextBytesMethod · 0.80
isValidMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected