PL/SQL Packages and Types Reference 10g Release 1 (10.1) Part Number B1080201 


View PDF 
The DBMS_RANDOM
package provides a builtin random number generator. DBMS_RANDOM
is not intended for cryptography.
This chapter contains the following topics:
This package should be installed as SYS. By default, the package is initialized with the current user name, current time down to the second, and the current session.
DBMS_RANDOM.RANDOM
produces integers in [2^^31, 2^^31).DBMS_RANDOM.VALUE
produces numbers in [0,1) with 38 digits of precision.DBMS_RANDOM can be explicitly initialized, but does not need to be initialized before calling the random number generator. It will automatically initialize with the date, userid, and process id if no explicit initialization is performed.
If this package is seeded twice with the same seed, then accessed in the same way, it will produce the same results in both cases.
In some cases, such as when testing, you may want the sequence of random numbers to be the same on every run. In that case, you seed the generator with a constant value by calling one of the overloads of DBMS_RANDOM.SEED
. To produce different output for every run, simply to omit the call to "Seed" and the system will choose a suitable seed for you.
Note: The INITIALIZE Procedure, RANDOM Procedure and the TERMINATE Procedure are all obsolete and, while currently supported, are included in this release for legacy reasons only. 
This procedure initializes the generator (but see Usage Notes).
DBMS_RANDOM.INITIALIZE ( val IN BINARY_INTEGER);
PRAGMA restrict_references (initialize, WNDS)
Parameter  Description 


The seed number used to generate a random number. 
This procedure is obsolete as it simply calls the SEED Procedures.
This function returns random numbers in a standard normal distribution.
DBMS_RANDOM.NORMAL RETURN NUMBER;
PRAGMA restrict_references (normal, WNDS)
Parameter  Description 


Returns a random number. 
This procedure generates a random number (but see Usage Notes).
DBMS_RANDOM.RANDOM RETURN binary_integer;
PRAGMA restrict_references (random, WNDS)
Parameter  Description 


Returns a random integer greater or equal to power(2,31) and less than power(2,31). 
This procedure is obsolete and, although it is currently supported, it should not be used.
This procedure resets the seed.
DBMS_RANDOM.SEED ( seed IN BINARY_INTEGER); DBMS_RANDOM.SEED ( seed IN VARCHAR2);
PRAGMA restrict_references (seed, WNDS);
Parameter  Description 


Seed number or string used to generate a random number. 
The seed can be a string up to length 2000.
This function gets a random string.
DBMS_RANDOM.STRING opt IN CHAR, len IN NUMBER) RETURN VARCHAR2;
PRAGMA restrict_references (string, WNDS)
Parameter  Description 


Returns a 
When you are finished with the package, call the TERMINATE procedure (but see Usage Notes)
DBMS_RANDOM.TERMINATE
This procedure performs no function and, although it is currently supported, it is obsolete and should not be used.
The basic function gets a random number, greater than or equal to 0 and less than 1, with 38 digits to the right of the decimal (38digit precision). Alternatively, you can get a random Oracle number x, where x is greater than or equal to low
and less than high
.
DBMS_RANDOM.VALUE RETURN NUMBER; DBMS_RANDOM.VALUE( low IN NUMBER, high IN NUMBER) RETURN NUMBER;
Parameter  Description 


Returns an Oracle Number. 