Returns a random value between 0 and 1, which is generated using the specified seed value, and computed for each returned row when used in the select list. Unlike rand, it is computed for each returned row when it is used in the select list.






  • The behavior of rand2 in places other than the select list is undefined.

  • The rand and rand2 functions use the output of a 32-bit pseudorandom integer generator. The integer is divided by the maximum 32-bit integer to give a double value between 0.0 and 1.0. and2 is seeded randomly at server start-up, so getting the same sequence of random numbers is unlikely, unless the user first initializes this function with a constant seed value.

    The rand2 function is a global resource.

    Multiple users calling the rand2 function progress along a single stream of pseudorandom values. If a repeatable series of random numbers is needed, the user must assure that the function is seeded with the same value initially and that no other user calls rand while the repeatable sequence is desired.

See also Transact-SQL Users Guide.


ANSI SQL – Compliance level: Transact-SQL extension.


Any user can execute rand2.

Related concepts
Approximate Numeric Datatypes
Related reference