Oracle PL/SQL Tutorial/System Packages/DBMS RANDOM
DBMS_RANDOM.INITIALIZE and DBMS_RANDOM.RANDOM
SQL>
SQL> DECLARE
2 lv_seed_num PLS_INTEGER := 123456789;
3 lv_random_num PLS_INTEGER;
4 BEGIN
5 DBMS_RANDOM.INITIALIZE(lv_seed_num);
6 FOR lv_loop_num IN 1..5 LOOP
7 lv_random_num := DBMS_RANDOM.RANDOM;
8 DBMS_OUTPUT.PUT_LINE("Loop: " || lv_loop_num ||
9 " Random Number: " || lv_random_num);
10 END LOOP;
11 DBMS_RANDOM.TERMINATE;
12 END;
13 /
Loop: 1 Random Number: 1476678237
Loop: 2 Random Number: -1196898280
Loop: 3 Random Number: -1383166668
Loop: 4 Random Number: 676298547
Loop: 5 Random Number: 1488158419
PL/SQL procedure successfully completed.
SQL>
DBMS_RANDOM.RANDOM()
SQL>
SQL>
SQL> SELECT DBMS_RANDOM.RANDOM()
2 FROM dual;
DBMS_RANDOM.RANDOM()
--------------------
-1.612E+09
SQL>