Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Random numbers
Nadav Zin wrote:
I need to generate random numbers in Oracle environment and could
not
find a straight forward way to do it. Has anyone got a PL/SQL code
to
share?
Cheers,
Please reply to: N.Zin_at_cs.ucl.ac.uk
Dear Zin,
I have the code at work where i did a rough random number generator.
Don't
go on the syntax of my code because i am new to pl/sql and don't know it
by heart. Basically what you do is declare a package like this:
create package random
seed NUMBER := 375737
inc NUMBER := 26791
procedure rough( max_number in number ); end random
create package body random
procedure rough( max_number in number ) is
simple_number
begin
seed := seed + inc; simple_number := mod( seed, max_number );end rough;
end random;
note that this is a bad random number generator but it will be okay for simple testing. you may have to play with it. the idea is very simple and simply goes on the fact that the easiest way to simulate random number is to use the remainder with a seed that is incremented by a large amount. if this doesn't work and you want some exact code i will be happy to send it to you. drop me a line tomorrow when i am at work and i will forward the package i wrote for rough random numbers.
tim Received on Wed Apr 16 1997 - 00:00:00 CDT