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 ) as Set Nocount On Declare @t table(num bigint) Declare @start bigint Declare @End bigint While @min<=@max Begin Insert into @t values(@min) set @min=@min+1 End 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
Tags: t-sql, sql_server, random_numbers,