Table 1 provides all interfaces supported by the DBMS_RANDOM package.
API |
Description |
|---|---|
Sets a seed for a random number. |
|
Generates a random number between a specified low and a specified high. |
The stored procedure SEED is used to set a seed for a random number. The DBMS_RANDOM.SEED function prototype is:
1 | DBMS_RANDOM.SEED (seed IN INTEGER); |
Parameter |
Description |
|---|---|
seed |
Generates a seed for a random number. |
The stored procedure VALUE generates a random number between a specified low and a specified high. The DBMS_RANDOM.VALUE function prototype is:
1 2 3 4 | DBMS_RANDOM.VALUE( low IN NUMBER, high IN NUMBER) RETURN NUMBER; |
Parameter |
Description |
|---|---|
low |
Sets the low bound for a random number. The generated random number is greater than or equal to the low. |
high |
Sets the high bound for a random number. The generated random number is less than the high. |
The only requirement is that the parameter type is NUMERIC regardless of the right and left bound values.
Generate a random number between 0 and 1:
1 | SELECT DBMS_RANDOM.VALUE(0,1); |
Generate a random integer ranging from 0 to 100. The random integer is greater than or equal to the specified value of low and less than the specified value of high.
1 | SELECT TRUNC(DBMS_RANDOM.VALUE(0,100)); |