## 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
e``````

Inherits from: Libraries.Language.Object

## Summary

### Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
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 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.

Example Code

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

#### Return

integer: 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(``````

#### 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(``````

#### Parameters

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

#### 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,``````

#### Parameters

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

#### 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(1``````

#### Parameters

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

#### 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(1``````

#### Parameters

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

#### 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 10100``````

#### Parameters

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