You are viewing documentation for an outdated version. It is no longer supported!

Math

Offers a few math related utility methods.

randomInt()

Generates a random number between given minimum and maximum values.

use Aedart\Utils\Math;

$value = Math::randomInt(1, 10);

seed()

Generates a value that can be used for seeding the random number generator.

use Aedart\Utils\Math;

$seed = Math::seed();

mt_srand($seed);

applySeed()

Seeds the Mersenne Twister Random Number Generator.

See PHP's documentationopen in new window for additional information.

use Aedart\Utils\Math;

$seed = 123456;
$list = ['a', 'b', 'c', 'd'];

Math::applySeed($seed);
$resultA = $list[ array_rand($list, 1) ];

Math::applySeed($seed);
$resultB = $list[ array_rand($list, 1) ];

echo $resultA; // b
echo $resultB; // b