Skip to main content

uniform function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 16.1 and later

Returns a random value with independent and identically distributed values within the specified range of numbers.

Syntax

uniform (boundaryExpr1, boundaryExpr2 [, seed] )

Arguments

  • boundaryExpr1: A SMALLINT, INT, BIGINT, or floating point constant expression, specifying an inclusive boundary of the range.
  • boundaryExpr2: A SMALLINT, INT, BIGINT, or floating point constant expression, specifying an inclusive boundary of the range.
  • seed: An optional SMALLINT, or INT expression serving as a seed for the random number generation.

Returns

A value of the least common type of boundaryExpr1 and boundaryExpr2.

Examples

SQL
> SELECT uniform(10, 20), uniform(10, 20) FROM range(10);
18 16
15 10
14 14
19 15
17 11
17 15
10 10
13 13
14 16
10 17

-- Using a fixed seed the series is deterministic
> SELECT uniform(10, 20, 0), uniform(10, 20, 0) FROM range(10);
10 10
11 11
19 19
18 18
19 19
14 14
18 18
14 14
10 10
17 17