Article View: borland.public.interbase.sql
Article #484How to use rand() function?
From: blackspace
Date: Thu, 06 Dec 2007 09:12
Date: Thu, 06 Dec 2007 09:12
40 lines
1677 bytes
1677 bytes
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>
Technical Details
Message-ID:
<20071206171256.d88a1845.blackspace@163.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,d0f8446ede906db,start X-Google-Attributes: gid114a0e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 6 Dec 2007 17:12:56 +0800 From: blackspace@163.com Newsgroups: borland.public.interbase.sql Subject: How to use rand() function? Message-ID: <20071206171256.d88a1845.blackspace@163.com> X-Newsreader: Sylpheed 2.4.7 (GTK+ 2.10.14; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 61.52.230.153 X-Trace: newsgroups.borland.com 1196932377 61.52.230.153 (6 Dec 2007 01:12:57 -0700) Lines: 40 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail