Functions for generating random numbers

**Arguments**

- `degree_of_freedom` — Degrees of freedom. [`Float64`](/docs/sql-reference/data-types/float)
- `x` — Optional and ignored. The only purpose of the argument is to prevent [common subexpression elimination](/docs/sql-reference/functions/overview#common-subexpression-elimination) when the same function call is used multiple times in a query. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns a random Float64 number drawn from the specified chi-square distribution. [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT randChiSquared(10) FROM numbers(5)
```

```
┌─randChiSquared(10)─┐
│ 10.015463656521543 │
│  9.621799919882768 │
│   2.71785015634699 │
│ 11.128188665931908 │
│  4.902063104425469 │
└────────────────────┘
```

## randConstant[​](#randConstant "Direct link to randConstant")

Introduced in: v1.1.0

Generates a single random value that remains constant across all rows in the current query execution.

This function:

- Returns the same random value for every row within a single query
- Produces different values across separate query executions

It is useful for applying consistent random seeds or identifiers across all rows in a dataset

**Syntax**

```
randConstant([x])
```

**Arguments**

- `x` — Optional and ignored. The only purpose of the argument is to prevent [common subexpression elimination](/docs/sql-reference/functions/overview#common-subexpression-elimination) when the same function call is used multiple times in a query. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns a column of type `UInt32` containing the same random value in each row. [`UInt32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Basic usage**

```
SELECT randConstant() AS random_value;
```

```
| random_value |
|--------------|
| 1234567890   |
```

**Usage with parameter**

```
SELECT randConstant(10) AS random_value;
```

```
| random_value |
|--------------|
| 9876543210   |
```

## randExponential[​](#randExponential "Direct link to randExponential")

Introduced in: v22.10.0

Returns a random Float64 number drawn from an [exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution).

**Syntax**

```
randExponential(lambda[, x])
```

**Arguments**

- `lambda` — Rate parameter or lambda value of the distribution [`Float64`](/docs/sql-reference/data-types/float)
- `x` — Optional and ignored. The only purpose of the argument is to prevent [common subexpression elimination](/docs/sql-reference/functions/overview#common-subexpression-elimination) when the same function call is used multiple times in a query. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns a random Float64 number drawn from the specified exponential distribution. [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT randExponential(1/10) FROM numbers(5)
```

```
┌─randExponential(divide(1, 10))─┐
│              44.71628934340778 │
│              4.211013337903262 │
│             10.809402553207766 │
│              15.63959406553284 │
│             1.8148392319860158 │
└────────────────────────────────┘
```

## randFisherF[​](#randFisherF "Direct link to randFisherF")

Introduced in: v22.10.0

Returns a random Float64 number drawn from an [F-distribution](https://en.wikipedia.org/wiki/F-distribution).

**Syntax**

```
randFisherF(d1, d2[, x])
```

**Arguments**

- `d1` — d1 degree of freedom in `X = (S1 / d1) / (S2 / d2)`. [`Float64`](/docs/sql-reference/data-types/float)
- `d2` — d2 degree of freedom in `X = (S1 / d1) / (S2 / d2)`. [`Float64`](/docs/sql-reference/data-types/float)
- `x` — Optional and ignored. The only purpose of the argument is to prevent [common subexpression elimination](/docs/sql-reference/functions/overview#common-subexpression-elimination) when the same function call is used multiple times in a query. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns a random Float64 number drawn from the specified F-distribution [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT randFisherF(10, 3) FROM numbers(5)
```

```
┌─randFisherF(10, 20)─┐
│  0.7204609609506184 │
│  0.9926258472572916 │
│  1.4010752726735863 │
│ 0.34928401507025556 │
│  1.8216216009473598 │
└─────────────────────┘
```

## randLogNormal[​](#randLogNormal "Direct link to randLogNormal")

Introduced in: v22.10.0

Returns a random Float64 number drawn from a [log-normal distribution](https://en.wikipedia.org/wiki/Log-normal_distribution).

**Syntax**

```
randLogNormal(mean, stddev[, x])
```

**Arguments**

- `mean` — The mean value of distribution. [`Float64`](/docs/sql-reference/data-types/float)
- `stddev` — The standard deviation of the distribution. [`Float64`](/docs/sql-reference/data-types/float)
- `x` — Optional and ignored. The only purpose of the argument is to prevent [common subexpression elimination](/docs/sql-reference/functions/overview#common-subexpression-elimination) when the same function call is used multiple times in a query. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns a random Float64 number drawn from the specified log-normal distribution. [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT randLogNormal(100, 5) FROM numbers(5)
```

```
┌─randLogNormal(100, 5)─┐
│  1.295699673937363e48 │
│  9.719869109186684e39 │
│  6.110868203189557e42 │
│  9.912675872925529e39 │
│ 2.3564708490552458e42 │
└───────────────────────┘
```

## randNegativeBinomial[​](#randNegativeBinomial "Direct link to randNegativeBinomial")

Introduced in: v22.10.0

Returns a random Float64 number drawn from a [negative binomial distribution](https://en.wikipedia.org/wiki/Negative_binomial_distribution).

**Syntax**

```
randNegativeBinomial(experiments, probability[, x])
```

**Arguments**

- `experiments` — The number of experiments. [`UInt64`](/docs/sql-reference/data-types/int-uint)
- `probability` — `The probability of failure in each experiment as a value between` 0`and`1`. [`Float64`](/sql-reference/data-types/float)
- `x` — Optional and ignored. The only purpose of the argument is to prevent [common subexpression elimination](/docs/sql-reference/functions/overview#common-subexpression-elimination) when the same function call is used multiple times in a query. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns a random Float64 number drawn from the specified negative binomial distribution [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT randNegativeBinomial(100, .75) FROM numbers(5)
```

```
┌─randNegativeBinomial(100, 0.75)─┐
│                              33 │
│                              32 │
│                              39 │
│                              40 │
│                              50 │
└─────────────────────────────────┘
```

## randNormal[​](#randNormal "Direct link to randNormal")

Introduced in: v22.10.0

Returns a random Float64 number drawn from a [normal distribution](https://en.wikipedia.org/wiki/Normal_distribution).

**Syntax**

```
randNormal(mean, stddev[, x])
```

**Arguments**

- `mean` — The mean value of distribution [`Float64`](/docs/sql-reference/data-types/float)
- `stddev` — The standard deviation of the distribution [`Float64`](/docs/sql-reference/data-types/float)
- `x` — Optional and ignored. The only purpose of the argument is to prevent [common subexpression elimination](/docs/sql-reference/functions/overview#common-subexpression-elimination) when the same function call is used multiple times in a query. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns a random Float64 number drawn from the specified normal distribution. [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT randNormal(10, 2) FROM numbers(5)
```

```
┌──randNormal(10, 2)─┐
│ 13.389228911709653 │
│  8.622949707401295 │
│ 10.801887062682981 │
│ 4.5220192605895315 │
│ 10.901239123982567 │
└────────────────────┘
```