Skip to main content

randstr

Returns a string of the specified length whose characters are chosen uniformly at random from the following pool of characters: 0-9, a-z, A-Z. The random seed is optional. The string length must be a constant two-byte or four-byte integer (SMALLINT or INT, respectively).

Added in Databricks Runtime 16.1

For the corresponding Databricks SQL function, see randstr function.

Syntax

Python
from pyspark.sql import functions as dbf

dbf.randstr(length=<length>, seed=<seed>)

Parameters

Parameter

Type

Description

length

pyspark.sql.Column or int

Number of characters in the string to generate.

seed

pyspark.sql.Column or int

Optional random number seed to use.

Parameter

Type

Description

length

pyspark.sql.Column or int

Number of characters in the string to generate.

seed

pyspark.sql.Column or int

Optional random number seed to use.

Returns

pyspark.sql.Column: The generated random string with the specified length.

Examples

Python
from pyspark.sql import functions as dbf
spark.range(0, 10, 1, 1).select(dbf.randstr(16, 3)).show()