Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: dbms_random question

Re: dbms_random question

From: Hans Forbrich <forbrich_at_telusplanet.net>
Date: Thu, 22 May 2003 16:00:19 GMT
Message-ID: <3ECCF2E2.4776C6F@telusplanet.net>


Pavel Vetesnik wrote:

> Hello,
>
> I want to generate a random number (to create an unique password). I
> thought, the dbms_random package was created for this purpouse.
>
> I use such code:
> ============================
> nMagic NUMBER(11);
>
> dbms_random.initialize(5);
> nMagic:=dbms_random.random;
> dbms_random.terminate;
> ============================
>
> But I always get the same number (1034085445 in this case)!
> Giving different 'seed' parameter (5 above), I can get different numbers,
> but the same 'seed' means the same number.
> So what that means? To create a random number I must pass a random number to
> the generator?!
>
> Please can you help me with this?
> Thank you in advance,
> Pavel

Random number generators in digital computing - as compared to analog computing and nature - are really psuedo-random. There are many algorithms available and some are better and some worse. But all tend to provide repeateable results given identical stimuli. In the more common algorithms, repeating the seed will repeat the result (which can be a good thing for test purposes).

Your solution of changing the seed for separate invocations is correct in general, regardless of the language you are using. To provide some variation in initialization, many programmers will use the clock/calendar (& some fancy calculations based on these) as the initialization seed.

(The randomize function in some languages needs a seed for every call. In those cases, consider using the results of the previous call as the seed for the new call.)

Some newer implementations have an 'initialize' function that uses the computer clock to make it even more random, and some of these even avoid using the seed externally. Based on other responses, I believe the Oracle package has been upgraded to this level after 8.1.6 and I believe that the random number generator is initialized during instance startup. More info is available in the docco. Received on Thu May 22 2003 - 11:00:19 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US