Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
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...|
+---+------------------+