hello,
How to generate list of random numbers passing values min and max
i have this store procedure i want to covert this to SQL function
create PROCEDURE [dbo].[Random_Number_Generator]
-- Add the parameters for the stored procedure here
@min_integer int
,@max_integer int
AS
BEGIN
begin try
drop table #rand_digits
end try
begin catch
print '#rand_digits not available to drop'
end catch
create table #rand_digits
(
rand_digit tinyint
)
-- declare min and max random digit values
-- and variables values to control loop count
declare
@loop_ctr int = 0
,@max_loop_ctr int = 1000
-- loop 1000 times
while @loop_ctr < @max_loop_ctr
begin
-- generate a random digit from @min_integer through @max_integer
-- and insert it into #rand_digits
insert #rand_digits(rand_digit)
select floor(rand()*(@max_integer - @min_integer + 1) + @min_integer)
set @loop_ctr = @loop_ctr + 1
end
-- count the number of each randomly computed digit
-- and display the results
select rand_digit, count(*) [frequency]
from #rand_digits
group by rand_digit
--order by rand_digit
order by newid()
END