You need to enable JavaScript to run this app.
ByteHouse Cloud Data Warehouse Version

ByteHouse Cloud Data Warehouse Version

Copy page
Download PDF
Function reference
Random functions
Copy page
Download PDF
Random functions

rand

Returns a pseudo-random UInt32 number, uniformly distributed among all UInt32 values.
Uses a linear congruential generator.
Syntax

rand([x])

Parameter

  • x — An expression that evaluates to any supported data type. The result value will be discarded, but if the function is called multiple times within a query, the expression itself can be used to bypass common subexpression elimination. Optional parameter.

Return value

  • Pseudo-random UInt32 number. Type: UInt32

Example

SELECT rand(), rand(number) FROM numbers(2);
┌─rand()─────┬─rand(number)─┐ 
│ 3882830473 │ 2236253349   │ 
│ 4122795699 │ 3720179576   │ 
└────────────┴──────────────┘

rand64

Returns a pseudo-random UInt64 number, uniformly distributed among all UInt64 values.
Uses a linear congruential generator.
Syntax

rand64([x])

Parameter

  • x — An expression that evaluates to any supported data type. The result value will be discarded, but if the function is called multiple times within a query, the expression itself can be used to bypass common subexpression elimination. Optional parameter.

Return value

  • Pseudo-random UInt64 number. Type: UInt64

Example

SELECT rand64(), rand64(number) FROM numbers(2);
┌─rand64()────────────┬─rand64(number)───────┐ 
│ 4216084906413806748 │ 17404981640646529534 │ 
│ 874879808660605772  │ 941470430861381566   │ 
└─────────────────────┴──────────────────────┘

randConstant

Generates a constant column with random values.
Syntax

randConstant([x])

Parameter

  • x — An expression that evaluates to any supported data type. The result value will be discarded, but if the function is called multiple times within a query, the expression itself can be used to bypass common subexpression elimination. Optional parameter.

Return value

  • Pseudo-random number. Type: UInt32.

Example

SELECT rand(), rand(1), rand(number), randConstant(), randConstant(1), randConstant(number) 
FROM numbers(3)
┌─rand()─────┬─rand(1)────┬─rand(number)─┬─randConstant()─┬─randConstant(1)─┬─randConstant(number)─┐ 
│ 1617218167 │ 3030783952 │ 3660442590   │ 3335999329     │ 1508515848      │ 1880875990           │ 
│ 432450540  │ 2987789840 │ 653572307    │ 3335999329     │ 1508515848      │ 1880875990           │ 
│ 3698169875 │ 79826010   │ 458167070    │ 3335999329     │ 1508515848      │ 1880875990           │ 
└────────────┴────────────┴──────────────┴────────────────┴─────────────────┴──────────────────────┘
Last updated: 2026.03.31 16:14:29