Hi

On 7/7/22 17:52, Go Kudo wrote:
Implementation is now proceeding.
It includes fixes to some of the issues that were pointed out previously.

https://github.com/php/php-src/pull/8094

`Randomizer::arrayPickKeys()` is currently not implemented for now, since
it is most likely to be rejected.
(Of course, we are ready to revert to the other items if they are also
rejected.)

I want to see if it looks good to you.

I've reviewed the current implementation of the engines with a specific focus on the tests.

1. I have verified the Xoshiro256** tests against a pure PHP implementation (which I verified against the C reference implementation [1]).

2. I have verified the Pcg64OneseqXslRr64 pcgoneseq128xslrr64_value.phpt test against the reference C implementation [2] with the attached pcg-verification.c.

3. I have verified the Mt19937 mt_value.phpt test against the C++ standard library implementation [3] with the attached mt-verification.cc.

The three engines do what they are supposed to do. I'm not qualified to review with regard to PHP Internals best practices. It would be good if someone with the necessary expertise could proceed with that part of the review.

Best regards
Tim Düsterhus

[1] https://prng.di.unimi.it/xoshiro256starstar.c
[2] https://www.pcg-random.org/download.html#c-implementation
[3] https://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine
#include <stddef.h>
#include <stdio.h>
#include "include/pcg_variants.h"

int
main(void) {
	struct pcg_state_128 s;

	pcg_oneseq_128_srandom_r(&s, 1234);
	for (size_t i = 0; i < 10000; i++)
		pcg_oneseq_128_xsl_rr_64_random_r(&s);
	
	for (size_t i = 0; i < 1234567; i++)
		pcg_oneseq_128_xsl_rr_64_random_r(&s);
	
	uint64_t result = pcg_oneseq_128_xsl_rr_64_random_r(&s);

	printf("Expected: b88e2a0f23720a1d\n");
	printf("Actual  : ");
	for (size_t i = 0; i < 64; i += 8)
		printf("%02llx", (result >> i) & 0xffULL);
	printf("\n");
}
#include <random>
#include <iostream>

int
main(void) {
	std::mt19937 g;
	g.seed(1234);

	for (auto i = 0; i < 10000; i++) g();

	int32_t result = g();

	std::cout << "Expected: 60fe95d9" << std::endl;
	std::cout << "Actual  : ";
	for (auto i = 0; i < 32; i += 8)
		std::cout << std::hex << ((result >> i) & 0xff);
	std::cout << std::endl;
}
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to