Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/randombytes.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/randombytes/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
randomBytes( int )
Note
A module with a better and standard API exists.
The crypto module partially implements the WebCrypto API, 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.
| Parameter | Type | Description |
|---|---|---|
| int | integer | The length of the returned ArrayBuffer. |
Returns
| Type | Description |
|---|---|
| ArrayBuffer | An 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,...
}Was this page helpful?
Related resources from Grafana Labs

