The DBMS_RANDOM package provides a built-in random number generator. DBMS_RANDOM is not intended for cryptography.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Privileges
You must install this package as the SYS user. By default, the package is initialized by using the current username, current time accurate to seconds, and the current session.
Considerations
You can call
DBMS_RANDOM.RANDOMto generate an integer within the range of [-2^31,2^31).You can call
DBMS_RANDOM.VALUEto generate a number with 38 digits of precision in the range of [0,1).
DBMS_RANDOM can be explicitly initialized. However, you do not need to initialize DBMS_RANDOM before you call the random number generator. If you do not explicitly initialize DBMS_RANDOM, it automatically initializes itself by using the date, user ID, and process ID.
If you use the same seed to seed the package twice, and access it twice by using the same method, it will produce the same results in both cases.
In some cases, such as in testing, you might want the same sequence of random numbers on every run. To this end, you can call one of the overloads of DBMS_RANDOM.SEED to seed the generator with a constant value. If you want different output for every run, omit calling SEED, and the system will choose an appropriate seed for you.
Subprograms
The following table describes the DBMS_RANDOM subprograms supported by the current OceanBase Database version.
| Subprogram | Description |
|---|---|
| INITIALIZE | Initializes the package by using a seed. |
| NORMAL | Returns random numbers in a normal distribution. |
| RANDOM | Returns a random number. |
| SEED | Resets the seed. |
| STRING | Returns a random string. |
| TERMINATE | Terminates the package. |
| VALUE | Returns a random number in the range of [0,1), with 38 digits to the right of the decimal point (38-digit precision). However, an overloaded function gets a random number x that is greater than or equal to the minimum value and less than the maximum value. |