Menu
Scroll for more
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
Open source
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
JavaScript
JavaScript
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
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.