Re: dbms_random in trigger

From: Frank <fvanbortel_at_netscape.net>
Date: Sat, 26 Apr 2003 17:24:25 +0200
Message-ID: <3EAAA4A9.1070409_at_netscape.net>


[Quoted] Glen A Stromquist wrote:
> I have created a table with a field called "random' that will hold a
> random number that will be generated before insert via a simple trigger
> which consists of:
> ========================
> declare
> x number;
> begin
> x :=dbms_random.random;
> :new.random := x;
> end;
> =======================
>
> This works ok, but I'd like to limit the random numbers to the same
> range as rows in the table, and I'm not sure how to use the
> dbms_rand.initialize to accomplish this.

[Quoted] dbms_rand.initialize is a "random" seed start. Try a dbms_rand.initialize(0), and generate random numbers. Then, wait a while, and redo. See any differences?

Use dbms_random.initialize(to_number(to_char(sysdate, 'miss')));

So there's nothing with initialize that allows for a range. Check dbms_rand.value instead - it has a lower and upper limit: dbms_rand.value(lower, upper)

declare
  x number;
begin
  dbms_random.initialize(to_number(to_char(sysdate, 'miss')));   x :=dbms_random.value(1,3000); -- range defined from 1 to 3000   :new.random := x;
end;

-- 
Regards, Frank van Bortel
Received on Sat Apr 26 2003 - 17:24:25 CEST

Original text of this message