Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================]
- Explanation: Random() with support for negative Range.
- [==============================================================================}
- function Random2(Range: Integer): Integer;
- begin
- if (Range <> 0) then
- if (Range > 0) then
- Result := Random(Range)
- else
- Result := (Random(IAbs(Range)) * -1);
- end;
- var
- TIA: TIntArray;
- i: Integer;
- begin
- ClearDebug;
- SetLength(TIA, 10);
- for i := 0 to 9 do
- TIA[i] := Random(10);
- WriteLn('Positives: ' + TIAToStr(TIA));
- SetLength(TIA, 0);
- SetLength(TIA, 10);
- for i := 0 to 9 do
- TIA[i] := Random2(-10);
- WriteLn('Negatives: ' + TIAToStr(TIA));
- SetLength(TIA, 0);
- end.
Advertisement
Add Comment
Please, Sign In to add comment