* Returns a randomly chosen value or null if not applicable. * @param {Random} random Random number generator * @return {mixed} Randomly chosen value
(random)
| 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. |
nothing calls this directly
no test coverage detected