I know the code from the Standard Delphi programming goes like this:
randomize();
i := random(5,10); // where i is an integer.
Then the value of i
will be between 5 and 10. However how would I do that in Fire Monkey. The function requires a range but I have no idea how to create the range.
Searching Google or event the documents on Embarcadero's website has been of no help either.
The function looks like this: function Random(const ARange: Integer): Integer;
Is this even possible, or am I looking the wrong places? Should I rather write a function like this:
while ((i<= 64) and (i>= 91)) do
i := Random(90);
The RNG functions in Delphi are part of the RTL, defined in the System
unit. As such the are available in FMX just as they are available in VCL. In short, FireMonkey is not really relevant.
The function that you are looking for is RandomRange
from System.Math
.
So, you might write:
Value := RandomRange(5, 10);
But note carefully this part of the documentation:
RandomRange returns a random integer from the range that extends between AFrom and ATo (non-inclusive).
So, the function call above can only return the following values: 5, 6, 7, 8 and 9.