Generate Random Numbers


This procedure will display n random numbers selected from specified range

Pass Starting Number, Ending Number and the number of numbers you want to select randomly

Create Procedure RandomNumbers (@min bigint, @max bigint, @count int)
Set Nocount On

Declare @t table(num bigint)
Declare @start bigint
Declare @End bigint

While @min<=@max

Insert into @t values(@min)
set @min=@min+1

Set Rowcount @count
Select num from @t order by newid()
Set Rowcount 0


If you run the below code

Exec RandomNumbers 100,300,10

10 random numbers between 100 and 300 will be displayed


Published Monday, August 27, 2007 4:23 PM by Madhivanan


No Comments