Updated on 2024-10-14 GMT+08:00

DBE_RANDOM

Interface Description

Table 1 lists all interfaces supported by the DBE_RANDOM package.

Table 1 DBE_RANDOM interface parameters

Interface

Description

DBE_RANDOM.SET_SEED

Sets a seed for a random number.

DBE_RANDOM.GET_VALUE

Generates a random number between a specified low and a specified high.

  • DBE_RANDOM.SET_SEED

    The stored procedure SEED is used to set a seed for a random number. The function prototype of DBE_RANDOM.SET_SEED is as follows:

    1
    DBE_RANDOM.SET_SEED (seed  IN  INTEGER);
    
    Table 2 DBE_RANDOM.SET_SEED interface parameters

    Parameter

    Description

    seed

    Generates a seed for a random number.

  • DBE_RANDOM.GET_VALUE

    The stored procedure VALUE generates a random number between a specified low and a specified high. The function prototype of DBE_RANDOM.GET_VALUE is as follows:

    1
    2
    3
    4
    DBE_RANDOM.GET_VALUE(
    min  IN  NUMBER default 0,
    max  IN  NUMBER default 1)
    RETURN NUMBER;
    
    Table 3 DBE_RANDOM.GET_VALUE interface parameters

    Parameter

    Description

    min

    Sets the low bound for a random number. The generated random number is greater than or equal to min.

    max

    Sets the high bound for a random number. The generated random number is less than max.

  • The only requirement is that the parameter type is NUMERIC regardless of the right and left bound values.
  • DBE_RANDOM implements pseudo-random numbers. Therefore, if the initial value (seed) remains unchanged, the sequence of the pseudo-random numbers also remains unchanged.
  • The generated random number contains 15 valid digits.

Examples

1
2
3
4
5
-- Generate a random number between 0 and 1.
SELECT DBE_RANDOM.GET_VALUE(0,1);

-- For integers within a specified range, add the arguments min and max, and truncate the decimals from the result (the maximum value is not included as a possible value). Therefore, for integers from 0 to 99, you can use the following code:
SELECT TRUNC(DBE_RANDOM.GET_VALUE(0,100));