ClickHouse/docs/en/sql-reference/functions/random-functions.md
BayoNet f2e2e993e5
DOCS-289: randConstant (#10838)
* DOCSUP-778 (#111)

* docs(randConstant): add description

* docs(randConstant): edit link

* docs(randConstant): corrections after review

* docs(randConstant): add description in Russian

Co-authored-by: egilmanova <egilmanova@yandex-team.ru>

* CLICKHOUSEDOCS-289: Updated descriptions.

* CLICKHOUSEDOCS-289: Fixed links.

* Update docs/ru/sql-reference/functions/random-functions.md

Co-authored-by: Ilya Yatsishin <2159081+qoega@users.noreply.github.com>

* Update docs/en/sql-reference/functions/random-functions.md

Co-authored-by: Ivan Blinkov <github@blinkov.ru>

Co-authored-by: egilmanova <63861789+egilmanova@users.noreply.github.com>
Co-authored-by: egilmanova <egilmanova@yandex-team.ru>
Co-authored-by: Sergei Shtykov <bayonet@yandex-team.ru>
Co-authored-by: Ilya Yatsishin <2159081+qoega@users.noreply.github.com>
Co-authored-by: Ivan Blinkov <github@blinkov.ru>
2020-05-12 19:37:21 +03:00

2.5 KiB

toc_priority toc_title
51 Generating Pseudo-Random Numbers

Functions for Generating Pseudo-random Numbers

Non-cryptographic generators of pseudo-random numbers are used.

All the functions accept zero arguments or one argument. If an argument is passed, it can be any type, and its value is not used for anything. The only purpose of this argument is to prevent common subexpression elimination, so that two different instances of the same function return different columns with different random numbers.

rand

Returns a pseudo-random UInt32 number, evenly distributed among all UInt32-type numbers. Uses a linear congruential generator.

rand64

Returns a pseudo-random UInt64 number, evenly distributed among all UInt64-type numbers. Uses a linear congruential generator.

randConstant

Produces a constant column with a random value.

Syntax

randConstant([x])

Parameters

Returned value

  • Pseudo-random number.

Type: UInt32.

Example

Query:

SELECT rand(), rand(1), rand(number), randConstant(), randConstant(1), randConstant(number)
FROM numbers(3)

Result:

┌─────rand()─┬────rand(1)─┬─rand(number)─┬─randConstant()─┬─randConstant(1)─┬─randConstant(number)─┐
│ 3047369878 │ 4132449925 │   4044508545 │     2740811946 │      4229401477 │           1924032898 │
│ 2938880146 │ 1267722397 │   4154983056 │     2740811946 │      4229401477 │           1924032898 │
│  956619638 │ 4238287282 │   1104342490 │     2740811946 │      4229401477 │           1924032898 │
└────────────┴────────────┴──────────────┴────────────────┴─────────────────┴──────────────────────┘

Original article