Janilabo

Janilabo | RandomRange2()

Dec 11th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.48 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: RandomRange() with support for negative AFrom / ATo.                
  3. [==============================================================================}
  4. function RandomRange2(AFrom, ATo: Integer): Integer;
  5. begin
  6.   if (AFrom > ATo) then
  7.     Swap(AFrom, ATo);
  8.   if (AFrom < 0) then
  9.     Result := (Random(IAbs(ATo - AFrom)) + AFrom)
  10.   else
  11.     Result := (Random(ATo - AFrom) + AFrom);
  12. end;
Advertisement
Add Comment
Please, Sign In to add comment