Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Random Number

Re: Random Number

From: Borivoj Tydlitat <btydlitat_at_merlin.cz>
Date: 1997/10/06
Message-ID: <343899C8.152B@merlin.cz>#1/1

Someone wrote:
>
> The easiest way I know is to use some function on sysdate, such as the
> taking the lower bytes of the numeric form (the subsecond portion),
> squaring it, and then normalizing it to your range. The advantage of
> using time is it can be argued to be a truly random number when using a
> consistent range of the time for the expected intervals of the queries
> (grabbing one millisecond of 1000 through a RDBMS on a multi-tasking
> operating system is in fact a random event).
>
> NetAccess News wrote:
>
> > Can anyone tell me a fairly easy way to generate a psuedo random
> > number in
> > Oracle - must I use time?

Beware:
1) there is no subsecond portion of SYSDATE. At least on our 7.3, SYSDATE is rounded to secs.
You can use DBMS_UTILITY.GET_TIME function to get time with 0.01 sec resolution. Of course, if you call a routine like this in a loop, there is nothing random about the result. The iron is terribly fast today.

2) You do not get good random numbers by performing "randomly" looking operations. Getting good pseudorandom numbers is a piece of science (or art? :-) ). Probably the safest and simplest method is the linear congruential method (recently discussed here, also see Knuth or some good statistics or num. math book).

3) Think twice, whether you need RANDOM or PSEUDORANDOM numbers. Do you just want to get values with random, but predictable statistic properties, do you want each run of your program run to behave differently, or do you want your routine to have a behavior not predictable by a human operator?

Borivoj Tydlitat
Merlin Received on Mon Oct 06 1997 - 00:00:00 CDT

Original text of this message

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