---
title: "utils | Grafana k6 documentation"
description: "A collection of small utility functions useful during load testing with k6."
---

# utils

> Note
> 
> The source code for this library can be found in the [grafana/k6-jslib-utils](https://github.com/k6io/k6-jslib-utils) GitHub repository.

The `utils` module contains number of small utility functions useful in every day load testing.

Expand table

| Function                                                                                                                                      | Description                                                                                                                                                                                                                                                                                                                     |
|-----------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [check(val, sets, \[tags\])](/docs/k6/latest/javascript-api/jslib/utils/check/)                                                               | Drop-in replacement for [`check`](/docs/k6/latest/javascript-api/k6/check/) with support for async values.                                                                                                                                                                                                                      |
| [randomIntBetween(min, max)](/docs/k6/latest/javascript-api/jslib/utils/randomintbetween/)                                                    | Random integer in a given range                                                                                                                                                                                                                                                                                                 |
| [randomItem(array)](/docs/k6/latest/javascript-api/jslib/utils/randomitem/)                                                                   | Random item from a given array                                                                                                                                                                                                                                                                                                  |
| [randomString(length, \[charset\])](/docs/k6/latest/javascript-api/jslib/utils/randomstring/)                                                 | Random string of a given length, optionally selected from a custom character set                                                                                                                                                                                                                                                |
| [uuidv4()](/docs/k6/latest/javascript-api/jslib/utils/uuidv4/)                                                                                | Random UUID v4 in a string representation                                                                                                                                                                                                                                                                                       |
| [findBetween(content, left, right, \[repeat\])](/docs/k6/latest/javascript-api/jslib/utils/findbetween/)                                      | Extract a string between two surrounding strings                                                                                                                                                                                                                                                                                |
| [normalDistributionStages(maxVUs, durationSeconds, \[numberOfStages\])](/docs/k6/latest/javascript-api/jslib/utils/normaldistributionstages/) | Creates [stages](/docs/k6/latest/using-k6/k6-options/#stages) which will produce a normal distribution (bell-curve) of VUs for a test                                                                                                                                                                                           |
| getCurrentStageIndex                                                                                                                          | Get the index of the running stage as defined in the `stages` array options. It can be used only with the executors that support the `stages` option as [ramping-vus](/docs/k6/latest/using-k6/scenarios/executors/ramping-vus/) or [ramping-arrival-rate](/docs/k6/latest/using-k6/scenarios/executors/ramping-arrival-rate/). |
| tagWithCurrentStageIndex                                                                                                                      | Tag all the generated metrics in the iteration with the index of the current running stage.                                                                                                                                                                                                                                     |
| tagWithCurrentStageProfile                                                                                                                    | Tag all the generated metrics in the iteration with the computed profile for the current running stage.                                                                                                                                                                                                                         |

## Simple example

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import { sleep } from 'k6';
import http from 'k6/http';

import {
  randomIntBetween,
  randomString,
  randomItem,
  uuidv4,
  findBetween,
} from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';

export default function () {
  const res = http.post(`https://quickpizza.grafana.com/api/users`, {
    username: `user_${randomString(10)}@example.com`, // random email address,
    password: uuidv4(), // random password in form of uuid
  });

  // find a string between two strings to grab the username:
  const username = findBetween(res.body, '"username":"', '"');
  console.log('username from response: ' + username);

  sleep(randomIntBetween(1, 5)); // sleep between 1 and 5 seconds.
}
```
