title: How do I generate random number with a range X times in SQL SERVER
body: <p>I want to generate a random number X times with a range. I've tried to create a function:</p>
  
  <pre><code>CREATE FUNCTION Random_Number (@Times INT, @Upper BIGINT,@Lower BIGINT, @randomvalue numeric(18,10))
  RETURNS INT
  AS
  BEGIN
      DECLARE @Random BIGINT
      DECLARE @Row INT
  
      SET @Row = 1
  
      WHILE  @Row &lt;= @Times
      BEGIN
          SELECT @Random = ROUND(((@Upper - @Lower -1) * @randomvalue + @Lower), 0)
          SET @Row = @Row + 1
      END
      RETURN @Random
  END
  GO
  
  
  select dbo.Random_Number(5,2002100001,2002100010,RAND())
  </code></pre>
  
  <p>The query only returns a single row:</p>
  
  <pre><code>#1 2002100003
  </code></pre>
  
  <p>I want the following result:</p>
  
  <pre><code>#1 2002100003
  #2 2002100000
  #3 2002100009
  #4 2002100006
  #5 2002100007
  </code></pre>
  
  <p>Is it possible?</p>