Skip to content

Random Variables

Andrew Dobis edited this page Jun 18, 2021 · 4 revisions

Random Variables are fields inside of the Random Object that can take on values depending on a set of associated constraints. A random field can be added to a RandObj by declaring one of two types of variables:

  • Rand: Represents a regular random variable with repeatable values.
  • Randc: Represents a cyclic random variable without repeating values.

Regular Random Variable

These Random Variables can take any value, within the given min and max boundaries, that satisfies the set of constraints associated to it. The variable takes a new value every time its parent object uses the randomize method and can take the same value multiples times.

Here's an example of how to define one in a Random Object:

  val len: Rand = new Rand("len", 0, 10)

Cyclic Random Variables

Cyclic Random Variables are similar to regular ones, but cannot take the same value twice until all values in the given range have been used. This means that once a value is obtained, it will be removed from the set of possible future values. A Cyclic Random Variable can be added by declaring a Randc field inside a RandObj. For example:

  val noRepeat: Randc = Randc("noRepeat", 0, 1)

Using the Random Fields

Once the random variables are defined, one must associate Constraints to them. Once this is done, the values can be obtained by calling the field's value() method.

len.value()
noRepeat.value()

Next topic Constraints or return home

Clone this wiki locally