Random

chm.Random

This function generates a random string.

		  CREATE FUNCTION [chm].[Random]
(
	@type       NVARCHAR(MAX),
	@length     SMALLINT,
	@characters NVARCHAR(MAX)
)
RETURNS NVARCHAR (MAX)	
		

Parameters:

  • @type: type of random sequence generated. Possible values are:
    • Alpha: alphabetic (both upper and lower)
    • AlphaLow: alphabetic (only lower characters)
    • AlphaUp: alphabetic (only upper characters)
    • Num: digits
    • AlphaLowNum: digits or lower alphabetic characters
    • AlphaUpNum: digits or upper alphabetic characters
    • AlphaNum: digits or alphabetic characters (both lower and upper)
    • NumNoZero: any non-zero digits
    • Custom: custom character sets
  • @length: length of output string or number of random characters to be generated
  • @characters: Custom character set from which random characters should be choosen of when @type is Custom.

Example:

		  select chm.Random('alphaup', 6, '')		-- VRMJWL
	select chm.Random('num', 6, '')			-- 498052
	select chm.Random('alphanum', 6, '')		-- eQ8cun
	select chm.Random('Custom', 6, 'ABCDEF12345')  -- 3DCDB3