SETSEED

SETSEED is a function in SQL that is used to set the seed for the generation of random numbers within a database. It's an important tool for establishing a start point in data sets that require randomized entries, ensuring that the random numbers generated in any further operations are reproducible.

SETSEED(double precision);

  • double precision: This parameter is used to set the seed for the next `random()` or `random(n)` function call. The value should be between -1.0 and 1.0, inclusive. This seed value specifies a new starting point for the sequence of random numbers generated by the `random()` function.

Example

SELECT SETSEED(0.5);
SELECT RANDOM();

Output

setseed
---------
(1 row)
random
--------
0.287299
(1 row)

Explanation

SETSEED sets the seed for the next RANDOM command. The argument to SETSEED is a double precision number. The command SETSEED(0.5); sets the seed to 0.5. In the output, the setseed operation returns 1 row signifying seed was successfully set. In the next command RANDOM(), it returns a pseudorandom number based on the seed value.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.