Interface GKRandom

  • All Known Implementing Classes:
    GKARC4RandomSource, GKGaussianDistribution, GKLinearCongruentialRandomSource, GKMersenneTwisterRandomSource, GKRandomDistribution, GKRandomSource, GKShuffledDistribution

    public interface GKRandom
    A protocol for random sources that can generate random numbers. This is the minimal interface needed to consume random values from a source; concrete subclasses should be used for configuring the production of random values. The availability of deterministic random sources is critical to creating reliable gameplay mechanics. Ensure that systems that should not influence each other have unique random sources and avoid sharing sources unless absolutely needed. This protocol allows you to provide custom random sources from classes that are not able to derive from GKRandomSource directly.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean nextBool()
      Returns the next true or false value in the random sequence and moves ahead to the next one.
      long nextInt()
      Returns the next integer in the random sequence and moves ahead to the next one.
      long nextIntWithUpperBound​(long upperBound)
      Returns the next unsigned value in the random sequence that is less than upperBound.
      float nextUniform()
      Returns the next uniform float in the random sequence and moves ahead to the next one.
    • Method Detail

      • nextBool

        boolean nextBool()
        Returns the next true or false value in the random sequence and moves ahead to the next one. The value is either nonzero (true) or zero (false). Use this for simple boolean switches in logic that don't require fuzzy evaluation. For fuzzy evaluation use nextUniform. By default this should be based on nextIntWithUpperBound:. Implementations may base it on another representation if needed.
        See Also:
        nextUniform()
      • nextInt

        long nextInt()
        Returns the next integer in the random sequence and moves ahead to the next one. The value is in the range of [INT32_MIN, INT32_MAX]. The lower bits are not guaranteed to be random so please use another property for simple choices.
        See Also:
        nextBool(), nextUniform()
      • nextIntWithUpperBound

        long nextIntWithUpperBound​(long upperBound)
        Returns the next unsigned value in the random sequence that is less than upperBound. The value is in the range of [0, upperBound). Thus the value never equals or exceeeds upperBound. The unsigned nature and upper bound allows implementations to use logical shifts to return a value whose lower bits are more random than a similar call to nextInt. This is used to implement nextBool and nextUniform by default.
      • nextUniform

        float nextUniform()
        Returns the next uniform float in the random sequence and moves ahead to the next one. The value is in the range of [0.0, 1.0]. There is no weighting across the range so remapping this with a curve may give the best sampling distribution for your algorithm. By default this should be based on nextIntWithUpperBound:. Implementions may base it on another representation if needed.
        See Also:
        nextInt()