Logo

SQL Server RANDBETWEEN Function

Updated 2023-10-18 15:30:32.843000

Description

Use the scalar function RANDBETWEEN to calculate a random integer number between the numbers you specify.

Syntax

SELECT [westclintech].[wct].[RANDBETWEEN] (
   <@Bottom, float,>
 ,<@Top, float,>)

Arguments

@Bottom

is the smallest integer that could be returned. @Bottom is an expression of type float or of a type that can be implicitly converted to float.

@Top

is the largest integer that could be returned. @Top is an expression of type float or of a type that can be implicitly converted to float.

Return Type

float

Remarks

@Top and @Bottom will be truncated to integers.

RANDBETWEEN is non-deterministic, so results will vary.

Examples

SELECT wct.RANDBETWEEN(-100, 100);

Here is the result set.

column 1
-46