Skip to main content

random

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

For the corresponding Databricks SQL function, see random function.

Syntax

Python
from pyspark.databricks.sql import functions as dbf

dbf.random(seed=<seed>)

Parameters

Parameter

Type

Description

seed

int, optional

Seed value for the random generator.

Examples

Python
from pyspark.databricks.sql import functions as dbf
spark.range(0, 2, 1, 1).select("*", dbf.rand()).show() # doctest: +SKIP
Output
+---+-------------------------+
| id|rand(-158884697681280011)|
+---+-------------------------+
| 0| 0.9253464547887...|
| 1| 0.6533254118758...|
+---+-------------------------+

Python
from pyspark.databricks.sql import functions as dbf
spark.range(0, 2, 1, 1).select("*", dbf.rand(seed=42)).show() # doctest: +SKIP
Output
+---+------------------+
| id| rand(42)|
+---+------------------+
| 0| 0.619189370225...|
| 1|0.5096018842446...|
+---+------------------+