#include "prx/libScePosixForWebKit/include/Api.hpp" #include "prx/libc/include/general/VabiMacros.hpp" #include #include #include #include #include #include #include void Require(bool condition, std::source_location location = std::source_location::current()) { if (!condition) { std::fprintf(stderr, "Posix random check failed at line %u\n", location.line()); std::abort(); } } int main() { std::array first{}; std::array second{}; first.fill(0xa5); arc4random_buf_nid_postfix(first.data(), 0); Require(std::all_of(first.begin(), first.end(), [](unsigned char value) { return value == 0xa5; })); for (const std::size_t size : {1u, 3u, 5u, 4098u}) { first.fill(0xa5); arc4random_buf_nid_postfix(first.data(), size); Require(std::all_of(first.begin() + static_cast(size), first.end(), [](unsigned char value) { return value == 0xa5; })); } arc4random_buf_nid_postfix(first.data(), first.size()); arc4random_buf_nid_postfix(second.data(), second.size()); Require(first != second); std::array counts{}; for (const auto value : first) ++counts[value]; Require(*std::max_element(counts.begin(), counts.end()) < 64); constexpr std::size_t Draws = 65536; static std::array words{}; for (auto& word : words) word = arc4random_nid_postfix(); std::array bits{}; std::array nibbles{}; for (const auto word : words) { for (std::size_t bit = 0; bit < bits.size(); ++bit) bits[bit] += (word >> bit) & 1u; ++nibbles[word >> 28]; } for (const auto count : bits) Require(count > Draws / 2 - 1500 && count < Draws / 2 + 1500); for (const auto count : nibbles) Require(count > Draws / 16 - 600 && count < Draws / 16 + 600); Require(*std::min_element(words.begin(), words.end()) < 0x00100000u); Require(*std::max_element(words.begin(), words.end()) > 0xfff00000u); std::sort(words.begin(), words.end()); std::size_t repeats = 0; for (std::size_t index = 1; index < Draws; ++index) repeats += words[index] == words[index - 1]; Require(repeats < 16); Require(arc4random_uniform_nid_postfix(0) == 0); Require(arc4random_uniform_nid_postfix(1) == 0); for (std::size_t index = 0; index < 1000; ++index) { Require(arc4random_uniform_nid_postfix(7) < 7); } std::array uniformCounts{}; for (std::size_t index = 0; index < 20000; ++index) { const auto value = arc4random_uniform_nid_postfix(10); Require(value < 10); ++uniformCounts[value]; } for (const auto count : uniformCounts) Require(count > 1500 && count < 2500); for (std::size_t index = 0; index < 100; ++index) { Require(arc4random_uniform_nid_postfix(0x80000000u) < 0x80000000u); } return 0; }