Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
function RandomFrom(const AValues: array of Double): Double; overload;
function RandomFrom(const AValues: array of Integer): Integer; overload;
function RandomFrom(const AValues: array of Int64): Int64; overload;
function RandomFrom(const AValues: array of string): string; overload;
Returns an element at random position from an array.
Note: when providing a "number" array and expecting a number as a result, you must use the Math unit. When working with string values you must use the StrUtils unit.
To initialize the random number generator, call (once) the Randomize procedure.
var
Years : array of integer;
aYear : integer;
SetLength(Years,6);
Years[0] := 1973; Years[1] := 1990; Years[2] := 1998;
Years[3] := 2000; Years[4] := 2003; Years[5] := 2008;
Randomize;
aYear := RandomFrom(Years);
|
Randomize, RandomRange, Random,
|
Free Delphi code snippet inside every Delphi Newsletter! |
|
|
|
Got some code to share? Got a question? Need some help? |
|
|