getRandomValues
Caution
The experimental module
k6/experimental/webcrypto
has graduated, and its functionality is now available globally through thecrypto
object. Thek6/experimental/webcrypto
is deprecated and will be removed in the near future.To migrate your scripts, remove the
k6/experimental/webcrypto
imports and use thecrypto
object instead.
The getRandomValues()
method fills the passed TypedArray
with cryptographically sound random values.
Usage
getRandomValues(typedArray)
Parameters
Return Value
The same array is passed as the typedArray
parameter with its contents replaced with the newly generated random numbers. The typedArray
parameter is modified in place, and no copy is made.
Throws
Example
import { crypto } from 'k6/experimental/webcrypto';
export default function () {
const array = new Uint32Array(10);
crypto.getRandomValues(array);
for (const num of array) {
console.log(num);
}
}