-
Hi,
Package for random number generation - DBMS_RANDOM generates same number each time I execute it - taking the same seed value. Following is the piece of code:
dbms_random.seed( 1 ) ;
rh := dbms_random.value(0, 10) ;
rm := dbms_random.value(1, 100) ;
dbms_random.terminate() ;
Is it required to take a different seed value each time I execute it ????
And ... what all procedures/functions are included in this package ??
Thanks in advance ....
-
dbms_random.initialize(12345); -- use at least a 5 digit number
create or replace procedure getrandom is
begin
dbms_output.put_line(dbms_random.random);
end;
/
SQL>execute getrandom
-1324234211
Don't reset the seed each time, and the random will work just fine. Procedures/functions include:
initialize, seed, random, terminate
See metalink article 1053864.6
-
Hi,
Try executing the following script :
/* Begin */
BEGIN
DECLARE
r1 NUMBER ;
r2 NUMBER ;
BEGIN
BEGIN
dbms_random.seed( 1234567890 ) ;
r1 := dbms_random.random() ;
r2 := dbms_random.random() ;
dbms_random.terminate() ;
DBMS_OUTPUT.PUT_LINE('R1 : '||r1|| ' R2 : '|| r2 ) ;
END ;
BEGIN
dbms_random.seed( 1234567890 ) ;
r1 := dbms_random.random() ;
r2 := dbms_random.random() ;
dbms_random.terminate() ;
DBMS_OUTPUT.PUT_LINE('R11 : '||r1|| ' R12 : '|| r2 ) ;
END ;
END ;
END ;
/* End */
Try on two different instances of SQL and check out the o/p.
Well, I used SYSDate and had my work done ...
Regards,
Pinakin.
-
Pinakin,
I can't see what is the point of your previous post.
Do you want to find out why your PL/SQL code is not working? You have to use DBMS_RANDOM.INITIALIZE to initialize your seed. If you have done so before you've run your anonymous block, then you should use it again after you used DBMS_RANDOM.TERMINATE in your first BEGIN-END block, if you wan't also the second part to succeed. Also, there is no particular need to change your seed very often (if at all) once you initialised it.
And what do you mean you have your work done by using SYSDATE? You mean you use SYDATE as a direct "semi-random" generator? If so, you could hardly treat that as a random generator.
Enlighten me if I'm missing the obvious....