Aller au contenu principal

rand

Génère une colonne aléatoire avec des échantillons indépendants et identiquement distribués (i.i.d.) uniformément répartis dans [0.0, 1.0). Prend en charge Spark Connect.

La fonction est non-déterministe dans le cas général.

Pour la fonction Databricks SQL correspondante, consultez la fonctionrand.

Syntaxe

Python
from pyspark.sql import functions as dbf

dbf.rand(seed=<seed>)

parameter

parameter

Type

Description

seed

int, optional

Graine pour le générateur aléatoire.

parameter

Type

Description

seed

int, optional

Graine pour le générateur aléatoire.

Renvoie

pyspark.sql.Column: Une colonne de valeurs aléatoires.

Exemples

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

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