> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# insecure-random-for-secret

> A sensitive token or secret uses a non-cryptographic random source.

## What it flags

`Math.random()` feeds a token, code, nonce, session or secret.

## How to review or fix

Use `crypto.randomBytes`, `randomInt` or `randomUUID`; names that only end in `id` are contextual. `Math.floor(Math.random() * N)` has a source fix.

## Example from the editor

```typescript theme={null}
import { randomBytes, randomInt } from 'node:crypto';
const resetToken = randomBytes(32).toString('hex');
const otp = randomInt(100000, 1000000);
```

Use crypto.randomBytes for tokens, crypto.randomInt for numeric codes and crypto.randomUUID for identifiers.

## Configuration

Set the rule to `"off"` in `loadwise.config.json` to drop its findings:

```json theme={null}
{
  "rules": { "insecure-random-for-secret": "off" }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.