Generate SQL statements of 300 different random numbers

Time:2021-9-12

–Generate 300 8-bit non repeating pure digital random numbers

DECLARE @i INT=0;
DECLARE @j INT;
DECLARE @qnum INT=300; -- Number of generated random numbers
SET NOCOUNT ON
CREATE TABLE #temp_Table(num INT)
WHILE(@i<@qnum)
BEGIN
  SELECT @j = cast( floor(rand()*(99999999-10000000)+10000000) as int) 
  IF(NOT EXISTS(SELECT num FROM #temp_Table WHERE [email protected] ))
  BEGIN
    INSERT #temp_Table (num) VALUES (@j)
    SET @i+=1;
  END 
END
SELECT DISTINCT num FROM #temp_Table
DROP TABLE #temp_Table