Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 rand( )

Author  Topic 

pravin14u
Posting Yak Master

246 Posts

Posted - 2004-07-12 : 06:17:11
Hi

i tried the rand() function without a seed value.It returned different set of values for different executions.So whats the difference in using a seed value and not using that with the rand() function?

thank you

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-07-12 : 08:33:45
Books Online is your friend. :)

RAND
Topic last updated -- July 2003

Returns a random float value from 0 through 1.

Syntax
RAND ( [ seed ] )

Arguments
seed

Is an integer expression (tinyint, smallint, or int) that specifies the seed value. If seed is not specified, Microsoft® SQL Server™ 2000 assigns a seed value at random. For a given seed value, the result returned is always the same.

Return Types
float

Remarks
Repetitive calls of RAND() with the same seed value in a single query return the same results.

For a connection, if RAND() is called with a specified seed value, all subsequent calls of RAND() produce results based on the seeded RAND() call. For example, the following query always returns the same sequence of numbers.

SELECT RAND(100), RAND(), RAND()

Examples
This example produces four different random numbers generated with the RAND function.

DECLARE @counter smallint
SET @counter = 1
WHILE @counter < 5
BEGIN
SELECT RAND() Random_Number
SET NOCOUNT ON
SET @counter = @counter + 1
SET NOCOUNT OFF
END
GO




MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -