| title | CRYPT_GEN_RANDOM (Transact-SQL) | ||
|---|---|---|---|
| description | CRYPT_GEN_RANDOM (Transact-SQL) | ||
| author | VanMSFT | ||
| ms.author | vanto | ||
| ms.date | 07/24/2017 | ||
| ms.service | sql | ||
| ms.subservice | t-sql | ||
| ms.topic | reference | ||
| ms.custom |
|
||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance FabricSQLDB]
This function returns a cryptographic, randomly-generated number, generated by the Crypto API (CAPI). CRYPT_GEN_RANDOM returns a hexadecimal number with a length of a specified number of bytes.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
CRYPT_GEN_RANDOM ( length [ , seed ] )
length
The length, in bytes, of the number that CRYPT_GEN_RANDOM will create. The length argument has an int data type, and a value range between 1 and 8000. CRYPT_GEN_RANDOM returns NULL for an int value outside this range.
seed
An optional hexadecimal number, for use as a random seed value. The length of seed must match the value of the length argument. The seed argument has a varbinary(8000) data type.
varbinary(8000)
This function is public and it does not require any special permissions.
This example generates a random number of length 50 bytes:
SELECT CRYPT_GEN_RANDOM(50) ; This example generates a random number of length 4 bytes, using a 4-byte seed:
SELECT CRYPT_GEN_RANDOM(4, 0x25F18060) ;