pyspark.sql.functions.randstr#
- pyspark.sql.functions.randstr(length, seed=None)[source]#
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).
New in version 4.0.0.
- Parameters
- Returns
Column
The generated random string with the specified length.
Examples
>>> spark.createDataFrame([('3',)], ['a']) \ ... .select(randstr(lit(5), lit(0)).alias('result')) \ ... .selectExpr("length(result) > 0").show() +--------------------+ |(length(result) > 0)| +--------------------+ | true| +--------------------+