---
title: "lint/style/prefer-random-int"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

<RuleId id="lint/style/prefer-random-int" />

In the [`modernize`](/docs/rules/sets/modernize) set. Unsafe fix: it can change behaviour.

## What it does

Replaces `rand`, `srand`, `getrandmax` functions calls with their `mt_*` analogs or `random_int`.

## Configuration

```toml title="pun.toml"
[lint.rules]
"style/prefer-random-int" = "error"
```

To skip it in some files, add an [override](/docs/configuration/pun-toml#lint) or a [`@pun-ignore-file`](/docs/configuration/ignore-comments) comment.

## Options

| Name | Type | Allowed values | Default | Upstream name |
| --- | --- | --- | --- | --- |
| `replacements` | `map` | Any | `{ "getrandmax" = "mt_getrandmax", "rand" = "mt_rand", "srand" = "mt_srand" }` | `replacements` |

## Replaces

- [`random_api_migration`](https://cs.symfony.com/doc/rules/alias/random_api_migration.html) (php-cs-fixer, risky)

[More lint/style rules](/docs/rules/lint/style) · [Edit this page](https://github.com/shipfastlabs/pun/edit/main/crates/pun-config/rules/mapping.toml)
