--- title: "CRYPT_GEN_RANDOM (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "07/24/2017" ms.prod: sql ms.prod_service: "database-engine, sql-database" ms.reviewer: "" ms.technology: t-sql ms.topic: "language-reference" f1_keywords: - "CRYPT_GEN_RANDOM_TSQL" - "CRYPT_GEN_RANDOM" dev_langs: - "TSQL" helpviewer_keywords: - "CRYPT_GEN_RANDOM function" ms.assetid: b74bd9d4-758e-4b94-89a0-76dcda6d8c42 author: VanMSFT ms.author: vanto --- # CRYPT_GEN_RANDOM (Transact-SQL) [!INCLUDE[tsql-appliesto-ss2008-asdb-xxxx-xxx-md](../../includes/tsql-appliesto-ss2008-asdb-xxxx-xxx-md.md)] 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. ![Topic link icon](../../database-engine/configure-windows/media/topic-link.gif "Topic link icon") [Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md) ## Syntax ```sql CRYPT_GEN_RANDOM ( length [ , seed ] ) ``` ## Arguments *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. ## Returned Types **varbinary(8000)** ## Permissions This function is public and it does not require any special permissions. ## Examples ### A. Generating a random number This example generates a random number of length 50 bytes: ```sql SELECT CRYPT_GEN_RANDOM(50) ; ``` This example generates a random number of length 4 bytes, using a 4-byte seed: ```sql SELECT CRYPT_GEN_RANDOM(4, 0x25F18060) ; ``` ## See also [RAND (Transact-SQL)](../../t-sql/functions/rand-transact-sql.md)