pyspark.sql.functions.rand

pyspark.sql.functions.rand(seed: Optional[int] = None) → pyspark.sql.column.Column

Generates a random column with independent and identically distributed (i.i.d.) samples uniformly distributed in [0.0, 1.0).

Notes

The function is non-deterministic in general case.

Examples

>>> df.withColumn('rand', rand(seed=42) * 3).collect()
[Row(age=2, name='Alice', rand=2.4052597283576684),
 Row(age=5, name='Bob', rand=2.3913904055683974)]