% rand_int.m    Generate random numbers until we get one that is almost an integer

% We use a variable that is 1 until we find what we are looking for.
flag = 1;
count = 0;
while flag == 1    % run thru the loop repeatedly until we get what we want.

  % Count how many random numbers must be generated before one is close to an integer.
  % count = count + 1;

  % Generate a random number.
  x = randn(1);

  % Determine if random number is close to an integer.
  if abs(x - round(x)) < 10^13*eps
    display('Found the random number approx equal integer')
    x = x  % Print the value of x.
    flag = 0;    % Set flag indicating we are done.  Causes end of loop next time 'while'
                 %  is encountered.
  end  % end of if

end  % end of while
