mirror of
https://github.com/php/php-src.git
synced 2026-04-18 21:41:22 +02: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
51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
--TEST--
|
|
Random: Randomizer: getFloat(): Basic functionality
|
|
--FILE--
|
|
<?php
|
|
|
|
use Random\Engine;
|
|
use Random\Engine\Mt19937;
|
|
use Random\Engine\PcgOneseq128XslRr64;
|
|
use Random\Engine\Secure;
|
|
use Random\Engine\Test\TestShaEngine;
|
|
use Random\Engine\Xoshiro256StarStar;
|
|
use Random\IntervalBoundary;
|
|
use Random\Randomizer;
|
|
|
|
require __DIR__ . "/../../engines.inc";
|
|
|
|
$engines = [];
|
|
$engines[] = new Mt19937(null, MT_RAND_MT19937);
|
|
$engines[] = new Mt19937(null, MT_RAND_PHP);
|
|
$engines[] = new PcgOneseq128XslRr64();
|
|
$engines[] = new Xoshiro256StarStar();
|
|
$engines[] = new Secure();
|
|
$engines[] = new TestShaEngine();
|
|
|
|
foreach ($engines as $engine) {
|
|
echo $engine::class, PHP_EOL;
|
|
|
|
$randomizer = new Randomizer($engine);
|
|
|
|
// Basic range test.
|
|
for ($i = 0.0; $i < 10_000.0; $i += 1.2345) {
|
|
$result = $randomizer->getFloat(-$i, $i, IntervalBoundary::ClosedClosed);
|
|
|
|
if ($result > $i || $result < -$i) {
|
|
die("failure: out of range at {$i}");
|
|
}
|
|
}
|
|
}
|
|
|
|
die('success');
|
|
|
|
?>
|
|
--EXPECT--
|
|
Random\Engine\Mt19937
|
|
Random\Engine\Mt19937
|
|
Random\Engine\PcgOneseq128XslRr64
|
|
Random\Engine\Xoshiro256StarStar
|
|
Random\Engine\Secure
|
|
Random\Engine\Test\TestShaEngine
|
|
success
|