1 PACKAGE dbms_random AUTHID DEFINER AS
2
3 ------------
4 -- OVERVIEW
5 --
6 -- This package should be installed as SYS. It generates a sequence of
7 -- random 38-digit Oracle numbers. The expected length of the sequence
8 -- is about power(10,28), which is hopefully long enough.
9 --
10 --------
11 -- USAGE
12 --
13 -- This is a random number generator. Do not use for cryptography.
14 -- For more options the cryptographic toolkit should be used.
15 --
16 -- By default, the package is initialized with the current user
17 -- name, current time down to the second, and the current session.
18 --
19 -- If this package is seeded twice with the same seed, then accessed
20 -- in the same way, it will produce the same results in both cases.
21 --
22 --------
23 -- EXAMPLES
24 --
25 -- To initialize or reset the generator, call the seed procedure as in:
26 -- execute dbms_random.seed(12345678);
27 -- or
28 -- execute dbms_random.seed(TO_CHAR(SYSDATE,'MM-DD-YYYY HH24:MI:SS'));
29 -- To get the random number, simply call the function, e.g.
30 -- my_random_number BINARY_INTEGER;
31 -- my_random_number := dbms_random.random;
32 -- or
33 -- my_random_real NUMBER;
34 -- my_random_real := dbms_random.value;
35 -- To use in SQL statements:
36 -- select dbms_random.value from dual;
37 -- insert into a values (dbms_random.value);
38 -- variable x NUMBER;
39 -- execute :x := dbms_random.value;
40 -- update a set a2=a2+1 where a1 < :x;
41
42 -- Seed with a binary integer
43 PROCEDURE seed(val IN BINARY_INTEGER);
44 PRAGMA restrict_references (seed, WNDS);
45
46 -- Seed with a string (up to length 2000)
47 PROCEDURE seed(val IN VARCHAR2);
48 PRAGMA restrict_references (seed, WNDS);
49
50 -- Get a random 38-digit precision number, 0.0 <= value < 1.0
51 FUNCTION value RETURN NUMBER PARALLEL_ENABLE;
52 PRAGMA restrict_references (value, WNDS);
53
54 -- get a random Oracle number x, low <= x < high
55 FUNCTION value (low IN NUMBER, high IN NUMBER) RETURN NUMBER
56 PARALLEL_ENABLE;
57 PRAGMA restrict_references (value, WNDS);
58
59 -- get a random number from a normal distribution
60 FUNCTION normal RETURN NUMBER PARALLEL_ENABLE;
61 PRAGMA restrict_references (normal, WNDS);
62
63 -- get a random string
64 FUNCTION string (opt char, len NUMBER)
65 /* "opt" specifies that the returned string may contain:
66 'u','U' : upper case alpha characters only
67 'l','L' : lower case alpha characters only
68 'a','A' : alpha characters only (mixed case)
69 'x','X' : any alpha-numeric characters (upper)
70 'p','P' : any printable characters
71 */
72 RETURN VARCHAR2 PARALLEL_ENABLE; -- string of <len> characters
73 PRAGMA restrict_references (string, WNDS);
74
75 -- external C function to record random value
76 PROCEDURE record_random_number(val IN NUMBER);
77 PRAGMA restrict_references (record_random_number, WNDS);
78
79 -- external C function to replay random value
80 FUNCTION replay_random_number RETURN NUMBER;
81 PRAGMA restrict_references (replay_random_number, WNDS);
82
83 -- Obsolete, just calls seed(val)
84 PROCEDURE initialize(val IN BINARY_INTEGER);
85 PRAGMA restrict_references (initialize, WNDS);
86
87 -- Obsolete, get integer in ( -power(2,31) <= random < power(2,31) )
88 FUNCTION random RETURN BINARY_INTEGER PARALLEL_ENABLE;
89 PRAGMA restrict_references (random, WNDS);
90
91 -- Obsolete, does nothing
92 PROCEDURE terminate;
93
94 TYPE num_array IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
95 END dbms_random;