Subject Re: [firebird-support] Rand function in ib_udf
Author Walter Ogston
Frank,

Thanks. I don't see srand in my version of ib_udf.sql, which came from the
December 2003 Firebird CD. I presume the updated version can be downloaded
- I'll do that sometime.

In the end I solved the problem by writing my own udf in delphi:

<code>
library WO_udf;

uses
System;

{$R *.res}

function WO_UDF_rand: double; stdcall
begin
Result := Random;
end;

exports
WO_UDF_rand;

begin
if RandSeed = 0 then
Randomize; // seeds the generator when the dll loads.
end.
</code>


At 07:19 PM 6/25/2004 +0200, you wrote:
>Walter Ogston wrote:
>
> > Ivan,
>
> > 2. Copy the .dll file into the udf folder along with fbudf.dll and
> ib_udf.dll
> >
> > 3. Drop old declaration of rand in database, and re-define referring to
> > the new dll. It looks to me that Firebird already knows the path to the
> > udf folder, but I don't see where this is set. Is it a hard-coded default?
> >
> > 4. Once it is working, send the code to someone for possible inclusion in
> > the next release.
> >
> > Any comments, traps, suggestions?
>
>There should be a working version in the actual snapshot build:
><http://firebird.sourceforge.net/download/snapshot_builds/win/fb20.zip>http
>://firebird.sourceforge.net/download/snapshot_builds/win/fb20.zip
>
>It contains:
>
>/*****************************************
> *
> * s r a n d
> *
> *****************************************
> *
> * Functional description:
> * Returns a random number between 0
> * and 1. Note the random number
> * generator is seeded using the current
> * time.
> *
> *****************************************/
>DECLARE EXTERNAL FUNCTION srand
> RETURNS DOUBLE PRECISION BY VALUE
> ENTRY_POINT 'IB_UDF_srand' MODULE_NAME 'ib_udf';
>
>/*****************************************
> *
> * r a n d
> *
> *****************************************
> *
> * Functional description:
> * Returns a random number between 0
> * and 1. Note: Use srand to seed the
> * random number generator.
> * This behavior has been changed.
> *****************************************/
>DECLARE EXTERNAL FUNCTION rand
> RETURNS DOUBLE PRECISION BY VALUE
> ENTRY_POINT 'IB_UDF_rand' MODULE_NAME 'ib_udf';
>
>
>You could replace your version of ib_udf.dll with the version from the
>zip-file.
>
>You will have to declare srand to your database and use this once to
>seed the generator.
>
>No more changes needed.
>
>hth
>Frank
>
>--
>"Fascinating creatures, phoenixes, they can carry immensely heavy loads,
> their tears have healing powers and they make highly faithful pets."
> - J.K. Rowling
>
>
>Yahoo! Groups Sponsor
>ADVERTISEMENT
>
>
>----------
>Yahoo! Groups Links
> * To visit your group on the web, go to:
> *
> <http://groups.yahoo.com/group/firebird-support/>http://groups.yahoo.com/g
> roup/firebird-support/
> *
> * To unsubscribe from this group, send an email to:
> *
> <mailto:firebird-support-unsubscribe@yahoogroups.com?subject=Unsubscribe>f
> irebird-support-unsubscribe@yahoogroups.com
> *
> * Your use of Yahoo! Groups is subject to the
> <http://docs.yahoo.com/info/terms/>Yahoo! Terms of Service.

/*----------------
C. Walter Ogston
ogstoncw@... Kalamazoo, Michigan
*/