Libraries.Compute.Random Documentation

The Random class permits generation of pseudorandom numbers that can be used for a variety of applications.

Example Code

use Libraries.Compute.Random

class Main
action Main
    // Print a list of ten random integers, each within the range 5 to 9.
    Random random
    repeat 10 times
        output random:RandomIntegerBetween(5, 9)
    end
end
end

Inherits from: Libraries.Language.Object

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

RandomBoolean()

This action returns a random boolean value. (True or False)

Return

boolean: Returns the random boolean.

Example

use Libraries.Compute.Random
Random random
boolean randomBool = random:RandomBoolean()

RandomInteger()

This action returns a random integer within the range 0 to +2,147,483,646 (lower bound inclusive, upper bound inclusive).

Return

integer: Returns the random number.

Example

use Libraries.Compute.Random
Random random
integer randomNumber = random:RandomInteger()

RandomInteger(integer maximum)

This action returns a random integer that is between zero (inclusive) and +2,147,483,646 (inclusive).

Parameters

  • integer maximum: - The maximum integer that can be generated.

Return

integer: Returns the random integer.

Example

use Libraries.Compute.Random
Random random
integer randomNumber = random:RandomInteger(5)

RandomIntegerBetween(integer minimum, integer maximum)

This action returns a random integer between minimum and maximum. Minimum and maximum are inclusive.

Parameters

  • integer minimum: The minimum number to be generated.
  • integer maximum: The maximum number to be generated.

Return

integer: Returns the random integer.

Example

use Libraries.Compute.Random
Random random
integer randomNumber = random:RandomIntegerBetween(1, 5)

RandomListOfIntegers(integer length)

This action returns a list of randomly generated integers in the range 0 to +2,147,483,646 (lower bound inclusive, upper bound inclusive).

Parameters

  • integer length: the length of the list to be generated.

Return

Libraries.Containers.List: Returns the list of random integers.

Example

use Libraries.Compute.Random
use Libraries.Containers.List
Random random
List<Integer> list
list = random:RandomListOfIntegers(15)

RandomListOfNumbers(integer length)

This action returns a list of randomly generated numbers in the range 0 to 1.

Parameters

  • integer length: the length of the list to be generated.

Return

Libraries.Containers.List: Returns the list of random numbers.

Example

use Libraries.Compute.Random
use Libraries.Containers.List
Random random
List<number> list
list = random:RandomListOfNumbers(15)

RandomNumber()

This action returns a random number within the range 0 to 1.

Return

number: Returns the random number.

Example

use Libraries.Compute.Random
Random random
number randomNumber = random:RandomNumber()

SetSeed(number seed)

This action sets the seed used to generate random numbers. On creation of a Random object, the seed is set to the current system time in milliseconds.

Parameters

  • number seed: The number that should be used as a seed. Note that the fractional portion of the number will be ignored.

Example

use Libraries.Compute.Random
Random random
random:SetSeed(1010001) // set the seed to 1010001