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

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns a CompareResult.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetHashCode()This action gets the hash code for an object.
RandomBoolean()This action returns a random boolean value.
RandomInteger()This action returns a random integer within the range 0 to +2,147,483,646 (lower bound inclusive, upper bound inclusive).
RandomInteger(integer maximum)This action returns a random integer that is between zero (inclusive) and +2,147,483,646 (inclusive).
RandomIntegerBetween(integer minimum, integer maximum)This action returns a random integer between minimum and maximum.
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).
RandomListOfNumbers(integer length)This action returns a list of randomly generated numbers in the range 0 to 1.
RandomNumber()This action returns a random number within the range 0 to 1.
SetSeed(number seed)This action sets the seed used to generate random numbers.

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns a CompareResult. The compare result is either larger if this hash code is larger than the object passed as a parameter, smaller, or equal.

Example Code

use Libraries.Language.Support.CompareResult
        Object o
        Object t
        CompareResult result = o:Compare(t)

Parameters

Return

Libraries.Language.Support.CompareResult: The Compare result, Smaller, Equal, or Larger.

Equals(Libraries.Language.Object object)

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

Example Code

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

Parameters

Return

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

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

RandomBoolean()

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

Example Code

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

Return

boolean: Returns the random boolean.

RandomInteger()

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

Example Code

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

Return

integer: Returns the random number.

RandomInteger(integer maximum)

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

Example Code

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

Parameters

Return

integer: Returns the random integer.

RandomIntegerBetween(integer minimum, integer maximum)

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

Example Code

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

Parameters

Return

integer: Returns the random integer.

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).

Example Code

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

Parameters

Return

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

RandomListOfNumbers(integer length)

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

Example Code

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

Parameters

Return

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

RandomNumber()

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

Example Code

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

Return

number: Returns the random number.

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.

Example Code

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

Parameters