Subject Re: [firebird-support] rand() of ib_udf not so random?
Author Ivan Prenosil
> I have the following procedure that is intended to return five
> random numbers:
>
> CREATE PROCEDURE R_NUM_LIST
> RETURNS
> (
> RNUMBER DOUBLE PRECISION
> )
> AS
> begin
> rNumber=rand();
> suspend;
> rNumber=rand();
> suspend;
> rNumber=rand();
> suspend;
> rNumber=rand();
> suspend;
> rNumber=rand();
> suspend;
> end
>
> The records returned when I do a SELECT RNUMBER FROM R_NUM_LIST have
> always the same number, repeated five times, although it is different
> every time I run it.
>
> I'm doing something erroneously?

Yes, you are using bad library :-)
Here is the source code of the gem you found


double EXPORT IB_UDF_rand()
{
srand( (unsigned)time (NULL));
return ((float) rand() / (float) RAND_MAX);
}


Ivan
http://www.volny.cz/iprenosil/interbase/