title: Use RAND() in User Defined Function
body: <p>I am trying to create a user defined function which calls the system <code>RAND()</code> function inside it, when I try to create the function it errors out with the following message:</p>
  
  <blockquote>
    <p>Msg 443, Level 16, State 1, Procedure getNumber, Line 10<br>
    Invalid use of a side-effecting operator 'rand' within a function.</p>
  </blockquote>
  
  <p>My function code:</p>
  
  <pre><code>CREATE FUNCTION getNumber(@_id int)
  RETURNS DECIMAL(18,4)
  AS
  BEGIN
     DECLARE @RtnValue DECIMAL(18,4);
  
     SELECT TOP 1 @RtnValue = EmployeeID 
     FROM dbo.Employees
     ORDER BY EmployeeID DESC
  
     SET @RtnValue = RAND() * @RtnValue * (1/100)
  
     RETURN @RtnValue;
  END
  </code></pre>
  
  <p>How can I fix this please? </p>