नोट
इस पेज तक पहुँच के लिए प्रमाणन की आवश्यकता होती है. आप साइन इन करने या निर्देशिकाओं को बदलने का प्रयास कर सकते हैं.
इस पेज तक पहुँच के लिए प्रमाणन की आवश्यकता होती है. आप निर्देशिकाओं को बदलने का प्रयास कर सकते हैं.
Generates a random column with independent and identically distributed (i.i.d.) samples uniformly distributed in [0.0, 1.0). Supports Spark Connect.
The function is non-deterministic in general case.
For the corresponding Databricks SQL function, see rand function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.rand(seed=<seed>)
Parameters
| Parameter | Type | Description |
|---|---|---|
seed |
int, optional |
Seed value for the random generator. |
Returns
pyspark.sql.Column: A column of random values.
Examples
from pyspark.databricks.sql import functions as dbf
spark.range(0, 2, 1, 1).select("*", dbf.rand()).show()
+---+-------------------------+
| id|rand(-158884697681280011)|
+---+-------------------------+
| 0| 0.9253464547887...|
| 1| 0.6533254118758...|
+---+-------------------------+
from pyspark.databricks.sql import functions as dbf
spark.range(0, 2, 1, 1).select("*", dbf.rand(seed=42)).show()
+---+------------------+
| id| rand(42)|
+---+------------------+
| 0| 0.619189370225...|
| 1|0.5096018842446...|
+---+------------------+