mirror of
https://github.com/php/php-src.git
synced 2026-03-26 09:12:14 +01:00
* random: Add Randomizer::nextFloat() * random: Check that doubles are IEEE-754 in Randomizer::nextFloat() * random: Add Randomizer::nextFloat() tests * random: Add Randomizer::getFloat() implementing the y-section algorithm The algorithm is published in: Drawing Random Floating-Point Numbers from an Interval. Frédéric Goualard, ACM Trans. Model. Comput. Simul., 32:3, 2022. https://doi.org/10.1145/3503512 * random: Implement getFloat_gamma() optimization see https://github.com/php/php-src/pull/9679/files#r994668327 * random: Add Random\IntervalBoundary * random: Split the implementation of γ-section into its own file * random: Add tests for Randomizer::getFloat() * random: Fix γ-section for 32-bit systems * random: Replace check for __STDC_IEC_559__ by compile-time check for DBL_MANT_DIG * random: Drop nextFloat_spacing.phpt * random: Optimize Randomizer::getFloat() implementation * random: Reject non-finite parameters in Randomizer::getFloat() * random: Add NEWS/UPGRADING for Randomizer’s float functionality
185 lines
4.4 KiB
PHP
185 lines
4.4 KiB
PHP
<?php
|
|
|
|
/** @generate-class-entries */
|
|
|
|
namespace {
|
|
/**
|
|
* @var int
|
|
* @cvalue MT_RAND_MT19937
|
|
*/
|
|
const MT_RAND_MT19937 = UNKNOWN;
|
|
/**
|
|
* @var int
|
|
* @cvalue MT_RAND_PHP
|
|
*/
|
|
const MT_RAND_PHP = UNKNOWN;
|
|
|
|
function lcg_value(): float {}
|
|
|
|
function mt_srand(int $seed = 0, int $mode = MT_RAND_MT19937): void {}
|
|
|
|
/** @alias mt_srand */
|
|
function srand(int $seed = 0, int $mode = MT_RAND_MT19937): void {}
|
|
|
|
function rand(int $min = UNKNOWN, int $max = UNKNOWN): int {}
|
|
|
|
function mt_rand(int $min = UNKNOWN, int $max = UNKNOWN): int {}
|
|
|
|
function mt_getrandmax(): int {}
|
|
|
|
/** @alias mt_getrandmax */
|
|
function getrandmax(): int {}
|
|
|
|
/** @refcount 1 */
|
|
function random_bytes(int $length): string {}
|
|
|
|
function random_int(int $min, int $max): int {}
|
|
}
|
|
|
|
namespace Random\Engine
|
|
{
|
|
/**
|
|
* @strict-properties
|
|
*/
|
|
final class Mt19937 implements \Random\Engine
|
|
{
|
|
public function __construct(int|null $seed = null, int $mode = MT_RAND_MT19937) {}
|
|
|
|
public function generate(): string {}
|
|
|
|
public function __serialize(): array {}
|
|
|
|
public function __unserialize(array $data): void {}
|
|
|
|
public function __debugInfo(): array {}
|
|
}
|
|
|
|
/**
|
|
* @strict-properties
|
|
*/
|
|
final class PcgOneseq128XslRr64 implements \Random\Engine
|
|
{
|
|
public function __construct(string|int|null $seed = null) {}
|
|
|
|
/** @implementation-alias Random\Engine\Mt19937::generate */
|
|
public function generate(): string {}
|
|
|
|
public function jump(int $advance): void {}
|
|
|
|
/** @implementation-alias Random\Engine\Mt19937::__serialize */
|
|
public function __serialize(): array {}
|
|
|
|
/** @implementation-alias Random\Engine\Mt19937::__unserialize */
|
|
public function __unserialize(array $data): void {}
|
|
|
|
/** @implementation-alias Random\Engine\Mt19937::__debugInfo */
|
|
public function __debugInfo(): array {}
|
|
}
|
|
|
|
/**
|
|
* @strict-properties
|
|
*/
|
|
final class Xoshiro256StarStar implements \Random\Engine
|
|
{
|
|
public function __construct(string|int|null $seed = null) {}
|
|
|
|
/** @implementation-alias Random\Engine\Mt19937::generate */
|
|
public function generate(): string {}
|
|
|
|
public function jump(): void {}
|
|
|
|
public function jumpLong(): void {}
|
|
|
|
/** @implementation-alias Random\Engine\Mt19937::__serialize */
|
|
public function __serialize(): array {}
|
|
|
|
/** @implementation-alias Random\Engine\Mt19937::__unserialize */
|
|
public function __unserialize(array $data): void {}
|
|
|
|
/** @implementation-alias Random\Engine\Mt19937::__debugInfo */
|
|
public function __debugInfo(): array {}
|
|
}
|
|
|
|
/**
|
|
* @strict-properties
|
|
* @not-serializable
|
|
*/
|
|
final class Secure implements \Random\CryptoSafeEngine
|
|
{
|
|
/** @implementation-alias Random\Engine\Mt19937::generate */
|
|
public function generate(): string {}
|
|
}
|
|
}
|
|
|
|
namespace Random
|
|
{
|
|
interface Engine
|
|
{
|
|
public function generate(): string;
|
|
}
|
|
|
|
interface CryptoSafeEngine extends Engine
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @strict-properties
|
|
*/
|
|
final class Randomizer
|
|
{
|
|
public readonly Engine $engine;
|
|
|
|
public function __construct(?Engine $engine = null) {}
|
|
|
|
public function nextInt(): int {}
|
|
|
|
public function nextFloat(): float {}
|
|
|
|
public function getFloat(float $min, float $max, IntervalBoundary $boundary = IntervalBoundary::ClosedOpen): float {}
|
|
|
|
public function getInt(int $min, int $max): int {}
|
|
|
|
public function getBytes(int $length): string {}
|
|
|
|
public function getBytesFromString(string $string, int $length): string {}
|
|
|
|
public function shuffleArray(array $array): array {}
|
|
|
|
public function shuffleBytes(string $bytes): string {}
|
|
|
|
public function pickArrayKeys(array $array, int $num): array {}
|
|
|
|
public function __serialize(): array {}
|
|
|
|
public function __unserialize(array $data): void {}
|
|
}
|
|
|
|
enum IntervalBoundary {
|
|
case ClosedOpen;
|
|
case ClosedClosed;
|
|
case OpenClosed;
|
|
case OpenOpen;
|
|
}
|
|
|
|
/**
|
|
* @strict-properties
|
|
*/
|
|
class RandomError extends \Error
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @strict-properties
|
|
*/
|
|
class BrokenRandomEngineError extends RandomError
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @strict-properties
|
|
*/
|
|
class RandomException extends \Exception
|
|
{
|
|
}
|
|
}
|