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:
seed parameter is not valid, JADE selects a new random seed value
range parameter exceeds Max_Integer - 1 (that is, 2,147,483,646), it is internally reset to 2,147,483,646
range parameter is less than zero (0), it is internally reset to zero (0), which forces the random31 method to return zero
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.