Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: DBMS_RANDOM
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.comReceived on Mon Mar 27 2000 - 11:16:24 CST