No results for

Powered byAlgolia
⚠️ This is the archived documentation for k6 v0.47. Go to the latest version.

randomBytes( int )

A module with a better and standard API exists

The new k6/experimental/webcrypto API partially implements the WebCryptoAPI, supporting more features than k6/crypto.

Return an ArrayBuffer object with a number of cryptographically random bytes. It will either return exactly the amount of bytes requested or will throw an exception if something went wrong.

ParameterTypeDescription
intintegerThe length of the returned ArrayBuffer.

Returns

TypeDescription
ArrayBufferAn ArrayBuffer with cryptographically random bytes.

Example

import crypto from 'k6/crypto';
export default function () {
const bytes = crypto.randomBytes(42);
const view = new Uint8Array(bytes);
console.log(view); // 156,71,245,191,56,...
}