random31

random31(seed:  Integer io;
         range: Integer): Integer;

The random31 method of the Application class returns a random positive number in the range 0 through the value of the range parameter, inclusive. Use this method to generate random numbers with a larger range of values compared to the Application class random method. In addition, the random31 method enables you to generate multiple sets of random numbers within a single application, by maintaining multiple values of the seed parameter.

The valid values for the seed parameter are in the range 1 through Max_Integer, inclusive. The valid values for the range parameter are in the range 0 through Max_Integer - 1, inclusive.

If the supplied value of the:

The method in the following example calls a method that uses the random31 method to generate a random letter.

testRandomLetters();
vars
    i : Integer;
    seed : Integer;
begin
    seed := app.clock;
    foreach i in 1 to 10 do
        getRandomLetter(seed);
    endforeach;
end;

Preserve the value of the seed parameter between calls to the random31 method by using a local variable as shown in the following example, or alternatively by making the seed parameter an attribute of an object.

getRandomLetter(seed: Integer io);
constants
    Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
begin
    write Letters[app.random31(seed, 25) + 1];
end;

See also the Application class random and seedRandom methods.