Package sim.engine

Class RandomSequence

java.lang.Object
sim.engine.Sequence
sim.engine.RandomSequence
All Implemented Interfaces:
Serializable, Steppable

public class RandomSequence extends Sequence
RandomSequence is a Sequence which executes its Steppable objects in random order each time.

The RandomSequence uses the random number generator to do its shuffling. If you use a RandomSequence within a ParallelSequence, or inside an AsynchronousSteppable, or in some other multithreaded condition, you should let the RandomSequence know this so that it will lock on the random number generator properly. This is done by setting the shouldSynchronize flag in the RandomSequence. Likewise, whenever in other threads you access the generator in a multithreaded context, you should have them synchronize on the generator first.

Be sure to read the class documentation on sim.engine.Sequence

See Also:
  • Constructor Details

    • RandomSequence

      public RandomSequence(Steppable[] steps)
      Creates an immutable RandomSequence. Does not synchronize before using the random number generator
    • RandomSequence

      public RandomSequence(Steppable[] steps, boolean shouldSynchronize)
      Creates an immutable RandomSequence. Synchronizes on the random number generator only if shouldSynchronize is true
    • RandomSequence

      public RandomSequence(Collection steps)
      Creates an immutable RandomSequence. Does not synchronize before using the random number generator
    • RandomSequence

      public RandomSequence(Collection steps, boolean shouldSynchronize)
      Creates an immutable RandomSequence. Synchronizes on the random number generator only if shouldSynchronize is true
  • Method Details

    • canEnsureOrder

      protected boolean canEnsureOrder()
      Description copied from class: Sequence
      If your subclass does not respect order, override this method to return false, and Sequence will ignore the ensuresOrder result.
      Overrides:
      canEnsureOrder in class Sequence
    • step

      public void step(SimState state)
      Specified by:
      step in interface Steppable
      Overrides:
      step in class Sequence