Oracle8i Supplied Packages Reference
Release 8.1.5

A68001-01

Library

Product

Contents

Index

Prev Next

30
DBMS_RANDOM

The DBMS_RANDOM package provides a built-in random number generator. It is faster than generators written in PL/SQL because it calls Oracle's internal random number generator.

Requirements

DBMS_RANDOM must be initialized prior to calling the random number generator. The generator produces 8 digit integers. If the initialization subprogram is not called, then the package raises an exception.

Summary of Subprograms

Table 30-1 DBMS_RANDOM Package Subprograms
Subprogram  Description 
INITIALIZE procedure
 

Initializes the package with a seed value.  

SEED procedure
 

Resets the seed.  

RANDOM function
 

Gets the random number.  

TERMINATE procedure
 

Closes the package.  

INITIALIZE procedure

To use the package, first call the initialize subprogram with the seed to use.

Syntax

DBMS_RANDOM.INITIALIZE (
   seed  IN  BINARY_INTEGER);


Note:

Use a seed that is sufficiently large, more than 5 digits. A single digit might not return sufficiently random numbers.  


Parameters

Table 30-2 INITIALIZE Procedure Parameters
Parameter  Description 
seed
 

Seed number used to generate a random number.  

SEED procedure

This procedure resets the seed.

Syntax

DBMS_RANDOM.SEED (
   seed  IN  BINARY_INTEGER);

Parameters

Table 30-3 INITIALIZE Procedure Parameters
Parameter  Description 

seed  

Seed number used to generate a random number.  

RANDOM function

This function gets the random number.

Syntax

DBMS_RANDOM.RANDOM
   RETURN BINARY_INTEGER;

Parameters

None.

Example

my_random_number := Random;

TERMINATE procedure

When you are finished with the package, call the TERMINATE procedure.

Syntax

DBMS_RANDOM.TERMINATE;

Parameters

None.




Prev

Next
Oracle
Copyright © 1999 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index