The DBMS_RANDOM package provides a built-in random number generator. DBMS_RANDOM is not used for encryption.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
Privilege requirements for DBMS_RANDOM
This package must be installed under the SYS user. By default, the package is initialized with the current username, current time (to the second), and current session.
Considerations for using DBMS_RANDOM
DBMS_RANDOM.RANDOMgenerates a random integer in the range [-2^31, 2^31).DBMS_RANDOM.VALUEgenerates a random number in the range [0, 1) with a precision of 38 decimal places.
DBMS_RANDOM can be explicitly initialized, but it is not required before calling the random number generator. If no explicit initialization is performed, it will automatically initialize using the date, user ID, and process ID.
If the package is seeded with the same seed value twice and accessed in the same way, the same results will be produced in both cases.
In some cases, such as during testing, you may want the random number sequence to be the same for each run. In this case, you can use the DBMS_RANDOM.SEED overload to implant a constant seed value. To generate different outputs for each run, simply omit the call to "Seed," and the system will choose an appropriate seed for you.
Subprograms of DBMS_RANDOM
The following table lists the DBMS_RANDOM subprograms supported by the current version of OceanBase Database and provides a brief description for each.
| Subprogram | Description |
|---|---|
| INITIALIZE | Initializes the package with a seed value. |
| NORMAL | Returns a random number following a normal distribution. |
| RANDOM | Generates a random number. |
| SEED | Resets the seed. |
| STRING | Retrieves a random string. |
| TERMINATE | Terminates the package. |
| VALUE | This function returns a random number that is greater than or equal to 0 and less than 1, with 38 decimal places of precision. The overloaded function returns a random number x, where x is greater than or equal to the minimum value and less than the maximum value. |
