Janilabo

Janilabo | Random2()

Dec 11th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.76 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Random() with support for negative Range.                
  3. [==============================================================================}
  4. function Random2(Range: Integer): Integer;
  5. begin
  6.   if (Range <> 0) then
  7.     if (Range > 0) then
  8.       Result := Random(Range)
  9.     else
  10.       Result := (Random(IAbs(Range)) * -1);
  11. end;
  12.  
  13. var
  14.   TIA: TIntArray;
  15.   i: Integer;
  16.  
  17. begin
  18.   ClearDebug;
  19.   SetLength(TIA, 10);
  20.   for i := 0 to 9 do
  21.     TIA[i] := Random(10);
  22.   WriteLn('Positives: ' + TIAToStr(TIA));
  23.   SetLength(TIA, 0);
  24.   SetLength(TIA, 10);
  25.   for i := 0 to 9 do
  26.     TIA[i] := Random2(-10);
  27.   WriteLn('Negatives: ' + TIAToStr(TIA));
  28.   SetLength(TIA, 0);
  29. end.
Advertisement
Add Comment
Please, Sign In to add comment