phaser - v4.0.0-rc.4
    Preparing search index...

    Class RandomDataGenerator

    A seeded Random Data Generator.

    Access via Phaser.Math.RND which is an instance of this class pre-defined by Phaser. Or, create your own instance to use as you require.

    The Math.RND generator is seeded by the Game Config property value seed. If no such config property exists, a random number is used.

    If you create your own instance of this class you should provide a seed for it. If no seed is given it will use a 'random' one based on Date.now.

    Index

    Constructors

    Properties

    signs: number[]

    Signs to choose from.

    Methods

    • Returns a random integer between and including min and max. This method is an alias for RandomDataGenerator.integerInRange.

      Parameters

      • min: number

        The minimum value in the range.

      • max: number

        The maximum value in the range.

      Returns number

    • Initialize the state of the random data generator.

      Parameters

      • seeds: string | string[]

        The seeds to initialize the random data generator with.

      Returns void

    • Returns a random integer between and including min and max.

      Parameters

      • min: number

        The minimum value in the range.

      • max: number

        The maximum value in the range.

      Returns number

    • Returns a random element from within the given array.

      Type Parameters

      • T

      Parameters

      • array: T[]

        The array to pick a random element from.

      Returns T

    • Returns a random real number between min and max.

      Parameters

      • min: number

        The minimum value in the range.

      • max: number

        The maximum value in the range.

      Returns number

    • Returns a random rotation in radians, between -3.141 and 3.141

      Returns number

    • Shuffles the given array, using the current seed.

      Type Parameters

      • T

      Parameters

      • Optionalarray: T[]

        The array to be shuffled.

      Returns T[]

    • Returns a sign to be used with multiplication operator.

      Returns number

    • Reset the seed of the random data generator.

      Note: the seed array is only processed up to the first undefined (or null) value, should such be present.

      Parameters

      • seeds: string[]

        The array of seeds: the toString() of each value is used.

      Returns void

    • Gets or Sets the state of the generator. This allows you to retain the values that the generator is using between games, i.e. in a game save file.

      To seed this generator with a previously saved state you can pass it as the seed value in your game config, or call this method directly after Phaser has booted.

      Call this method with no parameters to return the current state.

      If providing a state it should match the same format that this method returns, which is a string with a header !rnd followed by the c, s0, s1 and s2 values respectively, each comma-delimited.

      Parameters

      • Optionalstate: string

        Generator state to be set.

      Returns string

    • Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified.

      Parameters

      • min: number

        The minimum value in the range.

      • max: number

        The maximum value in the range.

      Returns number

    • Returns a random element from within the given array, favoring the earlier entries.

      Type Parameters

      • T

      Parameters

      • array: T[]

        The array to pick a random element from.

      Returns T