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: Jim Kennedy <kennedy-down_with_spammers_at_attbi.com>
Date: Thu, 22 May 2003 15:19:09 GMT
Message-ID: <NT5za.944066$F1.117195@sccrnsc04>


No, I am correct. Random number generators generate numbers that are with replacement.(they will repeat) In the case of THIS random number generator you need to give it a seed to start its sequence off. If you do not give it a seed then it always returns the same number. It is quite common to have a random number generator that will return a specific sequence once it has a specific seed. This is a feature. If you were doing QA then you might want a case that repeats its sequence of random numbers.

You need to understand that even with your seed it will repeat at some point. I've run into this misconception about random numbers quite often especially if people try to use them as a primary key. They are surprised when they get an error because the number has repeated.

Did you read the docs on this package?

Jim

-- 
Replace part of the email address: kennedy-down_with_spammers_at_attbi.com
with family.  Remove the negative part, keep the minus sign.  You can figure
it out.
"Pavel Vetesnik" <Pavel.Vet_at_volny.cz> wrote in message
news:baioad$2hp3$1_at_ns.felk.cvut.cz...

> Hi,
>
> thank you for your posting, but I guess, you are wrong - otherwise I was
> extremly lucky and got ten times the same number.
> After calling the
> ------------------
> dbms_random.initialize(5);
> dbms_random.random;
> ------------------
> I always got the 1034085445.
>
> But it is all right now - the
> ------------------
> dbms_random.initialize(TO_NUMBER(TO_CHAR(SYSDATE, 'SSSSS')));
> ------------------
> cured the problem. But it is question why use the dbms_random package and
> not call the TO_NUMBER(TO_CHAR(SYSDATE, 'SSSSS')) directly. It gives
> "random-enough" numbers :-)
>
> Pavel
>
> "Jim Kennedy" <kennedy-down_with_spammers_at_attbi.com> píše v diskusním
> příspěvku news:_25za.695898$Zo.149563_at_sccrnsc03...
> > Random does NOT mean without repeating. If you have a jar with 10
marbles
> > and each marble has a different number on it. The random number
generator
> > is like choosing a marble and then putting the marble back in the jar
and
> > choosing again. This is called choosing with replacement. You can get
> the
> > same number again. If you are looking for a random number generator
that
> > draws a new marble each time and the does not replace the marble back
into
> > the jar then you are going to have to keep track of all the marbles
drawn
> > and ignore those that came up before.
> > Jim
> >
> > --
> > Replace part of the email address: kennedy-down_with_spammers_at_attbi.com
> > with family. Remove the negative part, keep the minus sign. You can
> figure
> > it out.
> > "Pavel Vetesnik" <Pavel.Vet_at_volny.cz> wrote in message
> > news:baigpb$2e53$1_at_ns.felk.cvut.cz...
> > > 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
> > >
> > >
> >
> >
>
>
Received on Thu May 22 2003 - 10:19:09 CDT

Original text of this message

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