#include "prx/libc/include/general/VabiMacros.hpp" #include #include #include #include #include #include #include extern "C" void APS5_VABI arc4random_buf_nid_postfix(void*, std::size_t); extern "C" std::uint32_t APS5_VABI arc4random_nid_postfix(); 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); return 0; }