---
title: randstr function
description: Learn the syntax of the randstr function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/randstr
---

# `randstr` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 16.1 and above

Returns a random string of `length` alpha-numeric characters.

## Syntax

```
randstr ( length [, seed] )
```

## Arguments

* `length`: A `SMALLINT` or `INT` constant non-negative expression, specifying the length of the result string.
* `seed`: An optional `SMALLINT`, or `INT` expression serving as a seed for the random string generation.

## Returns

An `STRING` consisting of the characters `a-z`, `A-Z`, and `0-9`.

## Examples

```sql
> SELECT randstr(10), randstr(10);
  Xn2IiSepLX w3F34omh1C

-- Using a fixed seed, the outcome is deterministic series of random strings.
> SELECT randstr(10, 0), randstr(10, 0) FROM VALUES(1), (2), (3);;
  ceV0PXaR2I ceV0PXaR2I
  lBhHi56d0u lBhHi56d0u
  CtuwSOTLiL CtuwSOTLiL
```

## Related functions

* [`rand` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/rand.md)
* [`randn` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/randn.md)
* [`random` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/random.md)
* [`uniform` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/uniform.md)
