Groups > Interbase > Interbase SQL > I am sorry.




Re: How to use rand() function?

Re: How to use rand() function?
Thu, 6 Dec 2007 12:11:45 +0100
> It is Firebird-2.0.3.12981-1-Win32.exe that I use.

Then I suggest you take this question to a Firebird newsgroup
or support-mailinglist.

These are available at the Firebird website.


-- 
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com

Post Reply
How to use rand() function?
Thu, 6 Dec 2007 17:12:56 +0800
I want to use rand() function to get a random row from a FORTUNE table.
The function description tell me:"Note the random number generator is
seeded using the current time."
Why I always get same row? How I change the seed?

/*****************************************
 *
 *	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 rand 
	RETURNS DOUBLE PRECISION BY VALUE
	ENTRY_POINT 'IB_UDF_rand' MODULE_NAME 'ib_udf';


SET TERM ^ ;
ALTER PROCEDURE GET_RANDOM_FORTUNE
RETURNS (
    FORTUNE Varchar(1000) )
AS
BEGIN
  SELECT FIRST 1 FORTUNE 
    FROM FORTUNE 
    ORDER BY rand()
    INTO :FORTUNE;
  SUSPEND;   

END^
SET TERM ; ^


-- 
Post Reply
Re: How to use rand() function?
Thu, 6 Dec 2007 17:19:48 +0800
It is Firebird-2.0.3.12981-1-Win32.exe that I use.

On Thu, 6 Dec 2007 17:12:56 +0800
blackspace@163.com wrote:

> I want to use rand() function to get a random row from a FORTUNE table.
> The function description tell me:"Note the random number generator is
seeded using the current time."
> Why I always get same row? How I change the seed?
> 
> /*****************************************
>  *
>  *	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 rand 
> 	RETURNS DOUBLE PRECISION BY VALUE
> 	ENTRY_POINT 'IB_UDF_rand' MODULE_NAME 'ib_udf';
> 
> 
> SET TERM ^ ;
> ALTER PROCEDURE GET_RANDOM_FORTUNE
> RETURNS (
>     FORTUNE Varchar(1000) )
> AS
> BEGIN
>   SELECT FIRST 1 FORTUNE 
>     FROM FORTUNE 
>     ORDER BY rand()
>     INTO :FORTUNE;
>   SUSPEND;   
> 
> END^
> SET TERM ; ^
> 
> 
> -- 
>  <blackspace@163.com>


-- 
Post Reply
I am sorry.
Fri, 7 Dec 2007 10:24:24 +0800
On Thu, 6 Dec 2007 12:11:45 +0100
"Martijn Tonies" <m.tonies@upscene.removethis.com> wrote:

> > It is Firebird-2.0.3.12981-1-Win32.exe that I use.
> 
> Then I suggest you take this question to a Firebird newsgroup
> or support-mailinglist.
> 
> These are available at the Firebird website.
> 
> 
> -- 
> Martijn Tonies
> Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle
&
> MS SQL Server
> Upscene Productions
> http://www.upscene.com
> My thoughts:
> http://blog.upscene.com/martijn/
> Database development questions? Check the forum!
> http://www.databasedevelopmentforum.com
> 
> 


-- 
Post Reply
about | contact