Skip to main content
Skip to main content
Edit this page

Functions for Generating Random Numbers

All functions in this section accept zero or one arguments. The only use of the argument (if provided) is to prevent common subexpression elimination such that two different executions within a row of the same random function return different random values.

Related content

Note

The random numbers are generated by non-cryptographic algorithms.

rand

Returns a random UInt32 number with uniform distribution.

Uses a linear congruential generator with an initial state obtained from the system, which means that while it appears random, it's not truly random and can be predictable if the initial state is known. For scenarios where true randomness is crucial, consider using alternative methods like system-level calls or integrating with external libraries.

Syntax

Alias: rand32

Arguments

None.

Returned value

Returns a number of type UInt32.

Example

rand64

Returns a random UInt64 integer (UInt64) number

Syntax

Arguments

None.

Arguments

Returns a number UInt64 number with uniform distribution.

Uses a linear congruential generator with an initial state obtained from the system, which means that while it appears random, it's not truly random and can be predictable if the initial state is known. For scenarios where true randomness is crucial, consider using alternative methods like system-level calls or integrating with external libraries.

Example

randCanonical

Returns a random Float64 number.

Syntax

Arguments

None.

Arguments

Returns a Float64 value between 0 (inclusive) and 1 (exclusive).

Example

randConstant

Generates a single constant column filled with a random value. Unlike rand, this function ensures the same random value appears in every row of the generated column, making it useful for scenarios requiring a consistent random seed across rows in a single query.

Syntax

Arguments

  • [x] (Optional): An optional expression that influences the generated random value. Even if provided, the resulting value will still be constant within the same query execution. Different queries using the same expression will likely generate different constant values.

Arguments

Returns a column of type UInt32 containing the same random value in each row.

Implementation details

The actual output will be different for each query execution, even with the same optional expression. The optional parameter may not significantly change the generated value compared to using randConstant alone.

Example

randUniform

Returns a random Float64 drawn uniformly from interval [min, max].

Syntax

Arguments

  • min - Float64 - left boundary of the range,
  • max - Float64 - right boundary of the range.

Arguments

A random number of type Float64.

Example

randNormal

Returns a random Float64 drawn from a normal distribution.

Syntax

Arguments

  • mean - Float64 - mean value of distribution,
  • variance - Float64 - variance of the distribution.

Returned value

Example

Result:

randLogNormal

Returns a random Float64 drawn from a log-normal distribution.

Syntax

Arguments

  • mean - Float64 - mean value of distribution,
  • variance - Float64 - variance of the distribution.

Returned value

Example

Result:

randBinomial

Returns a random UInt64 drawn from a binomial distribution.

Syntax

Arguments

  • experiments - UInt64 - number of experiments,
  • probability - Float64 - probability of success in each experiment, a value between 0 and 1.

Returned value

Example

Result:

randNegativeBinomial

Returns a random UInt64 drawn from a negative binomial distribution.

Syntax

Arguments

  • experiments - UInt64 - number of experiments,
  • probability - Float64 - probability of failure in each experiment, a value between 0 and 1.

Returned value

Example

Result:

randPoisson

Returns a random UInt64 drawn from a Poisson distribution.

Syntax

Arguments

  • n - UInt64 - mean number of occurrences.

Returned value

Example

Result:

randBernoulli

Returns a random UInt64 drawn from a Bernoulli distribution.

Syntax

Arguments

  • probability - Float64 - probability of success, a value between 0 and 1.

Returned value

Example

Result:

randExponential

Returns a random Float64 drawn from a exponential distribution.

Syntax

Arguments

  • lambda - Float64 - lambda value.

Returned value

Example

Result:

randChiSquared

Returns a random Float64 drawn from a Chi-square distribution - a distribution of a sum of the squares of k independent standard normal random variables.

Syntax

Arguments

  • degree_of_freedom - Float64 - degree of freedom.

Returned value

Example

Result:

randStudentT

Returns a random Float64 drawn from a Student's t-distribution.

Syntax

Arguments

  • degree_of_freedom - Float64 - degree of freedom.

Returned value

Example

Result:

randFisherF

Returns a random Float64 drawn from a F-distribution.

Syntax

Arguments

  • d1 - Float64 - d1 degree of freedom in X = (S1 / d1) / (S2 / d2),
  • d2 - Float64 - d2 degree of freedom in X = (S1 / d1) / (S2 / d2),

Returned value

Example

Result:

randomString

Generates a string of the specified length filled with random bytes (including zero bytes). Not all characters may be printable.

Syntax

Arguments

  • length — String length in bytes. Positive integer.

Returned value

  • String filled with random bytes. String.

Example

Query:

Result:

randomFixedString

Generates a binary string of the specified length filled with random bytes (including zero bytes). Not all characters may be printable.

Syntax

Arguments

  • length — String length in bytes. UInt64.

Returned value(s)

Example

Query:

Result:

randomPrintableASCII

Generates a string with a random set of ASCII characters. All characters are printable. If you pass length < 0, the behavior of the function is undefined.

Syntax

Arguments

  • length — String length in bytes. Positive integer.

Returned value

  • String with a random set of ASCII printable characters. String

Example

randomStringUTF8

Generates a random string of a specified length. Result string contains valid UTF-8 code points. The value of code points may be outside of the range of assigned Unicode.

Syntax

Arguments

  • length — Length of the string in code points. UInt64.

Returned value(s)

  • UTF-8 random string. String.

Example

Query:

Result:

fuzzBits

Syntax

Flips the bits of String or FixedString s, each with probability prob.

Syntax

Arguments

  • s - String or FixedString,
  • prob - constant Float32/64 between 0.0 and 1.0.

Returned value

Fuzzed string with same type as s.

Example

Result: