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.

New in version 4.0.0.

Parameters
minColumn, int, or float

Minimum value in the range.

maxColumn, int, or float

Maximum value in the range.

seedColumn or int

Optional random number seed to use.

Returns
Column

The generated random number within the specified range.

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|
+------------------+