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

Re: DBMS_RANDOM

From: Mark Townsend <mtownsen_at_us.oracle.com>
Date: Mon, 27 Mar 2000 09:16:24 -0800
Message-ID: <38DF9768.E9588E85@us.oracle.com>


Van Messner wrote:
>
> DBMS_Random returns 8 digit integers until version 8.1.5. I don't have my
> 8.1.6 disks yet but how huge are the numbers you're seeing? With 8 digit
> numbers you can truncate/mod/etc to map the 8 digits into some number
> between 0 and 365,
>

[snip]
> > Does anybody use DBMS_RANDOM?
> >
> > My task is to have numbers randomly generated between 0 and 365 in PL/SQL.
> I
> > tried to use DBMS_RANDOM (8.1.6) but I couldn't understand how does it
> work.
> > The +/- numbers it generates are so huge and have no clear dependency on
> > SEED parameter that's only one available to adjust generating.
> >
> > Any idea?
> >
> > Thanks,
> > Eugene.

8.1.6 dbms_random has an overloaded call to the VALUE function that allows you to do what you want - try as follows

SQL> execute dbms_random.seed(to_char(sysdate,'MM-DD-YYYY HH24:MI:SS'));

PL/SQL procedure successfully completed.

SQL> select round(dbms_random.value(0,365),0) from dual;

ROUND(DBMS_RANDOM.VALUE(0,365),0)


                              333


--
Regards,

Mark Townsend                         

Principal Product Manager			Ph: 	(650) 633 5764
Server Division					Fx: 	(650) 506 7222
Oracle Corporation				Email:	mtownsen_at_us.oracle.com

Received on Mon Mar 27 2000 - 11:16:24 CST

Original text of this message

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