pyspark.sql.functions.uniform#

pyspark.sql.functions.uniform(min, max, seed=None)[source]#

Returns a random value with independent and identically distributed (i.i.d.) values with the specified range of numbers. The random seed is optional. The provided numbers specifying the minimum and maximum values of the range must be constant. If both of these numbers are integers, then the result will also be an integer. Otherwise if one or both of these are floating-point numbers, then the result will also be a floating-point number.

Added in version 4.0.0.

Parameters:
minColumn, int, or float

Minimum value in the range. A column that evaluates to a numeric. Must be a constant.

maxColumn, int, or float

Maximum value in the range. A column that evaluates to a numeric. Must be a constant.

seedColumn or int

Optional random number seed to use. A column that evaluates to an integer or long. Must be a constant.

Returns:
Column

The generated random number within the specified range. Returns a column of the same type as the input.

Examples

>>> import pyspark.sql.functions as sf
>>> spark.range(0, 10, 1, 1).select(sf.uniform(5, 105, 3)).show()
+------------------+
|uniform(5, 105, 3)|
+------------------+
|                30|
|                71|
|                99|
|                77|
|                16|
|                25|
|                89|
|                80|
|                51|
|                83|
+------------------+