On Sat, Nov 16, 2002 at 15:18:58 -0500,
Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Neil Conway <neilc@samurai.com> writes:
> > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> >> "Random" randomly fails. It is OK.
>
> > So why is it a regression test, then?
>
> It's hard to see how you could test random() in a completely
> deterministic fashion ...
You could use the floor function and check that function call works and
that returned values are in the range >= 0 and < 1 (the description just
says between but this is the normal range).
You could also do a couple of selects that compare random's output to
each other to see if it is generating a constant. The odds of this
happening by chance are very small. If you tie a couple of these
together you should be able to reduce the chances to whatever you
think is safe.
The odds of the following returning true should be less than the chances
of a hardware hiccup:
select random() = random() and random() = random();
The following should always return 0 (assuming I am right about random
being strictly less than 1):
select floor(random());
You can probably come up with other tricks. For example for a large sample
you should be able to put a bound on the average for which the probability
of the average being outside that bound is comparable to the test for
random returning constant values.
The variance is something else that could be tested this way.