Re: Random Number PL/SQL

From: <andreas_at_swog.fhcrc.org>
Date: 17 Dec 1998 22:40:40 GMT
Message-ID: <75c198$487$1_at_lore.eur.sprynet.com>


> don_at_veenet.value.net (Don Littlefield II) writes:
> Hello,
>
> Does anyone have a simple method of generating a random
> number in PL/SQL. I would have thought there would have
> been a routine to do this, but.. I have yet to find it.
>
> Best Regards, Don
>
>
>>>>   

     v_multiplier  CONSTANT NUMBER := 22695477;
        v_increment   CONSTANT NUMBER := 1;
        v_seed        NUMBER := 1;

     


       --  using the julian date plus the seconds elapsed since midnight to make seed

       select (to_number(to_char(sysdate,'J')) +                (to_number(to_char(sysdate,'SSSSS')))  )
	into v_seed from dual;

        dbms_output.put_line(" dateseed='||v_seed(;
       v_seed := mod(v_multiplier * v_seed + v_increment, (2 ** 32 ));
       p := bitand(v_seed/(2 ** 16), 32767);
       dbms_output.put_line(' seed='||v_seed||'   random='||p);
        j := mod(p, kw) +1 ;        --  kw is the range that you wish to be in like 1,100
Received on Thu Dec 17 1998 - 23:40:40 CET

Original text of this message