Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: dbms_random question
Pavel Vetesnik wrote:
> OK,
> so I've changed the code to this:
>
> ============================
> nMagic NUMBER(11);
>
> dbms_random.initialize(TO_NUMBER(TO_CHAR(SYSDATE, 'SSSSS')));
> nMagic:=dbms_random.random;
> dbms_random.terminate;
> ============================
>
> Then the numbers seems to change. But my question is - is this the correct
> way, how the generator should be used?
>
> Pavel
>
Based on your code sample, NO that is not the way to use random(). Why? Well, you are resetting the sequence everytime you call initialize(). The seed provides a way to start, and with a fixed value as you had in the original version, you always get the same first random number.
And you are using this to make a PASSWORD? You'll actually be better off using just the SYSDATE. Or make the user select some unique password.
-- Ed Prochak running http://www.faqs.org/faqs/running-faq/ netiquette http://www.psg.com/emily.html -- "Two roads diverged in a wood and I I took the one less travelled by and that has made all the difference." robert frostReceived on Thu May 22 2003 - 11:38:00 CDT
![]() |
![]() |