/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: RNG.hpp Date: 2021-6-10 Author: Reece ***/ #pragma once namespace Aurora::RNG { AUKN_SYM void ReadSecureRNG(void *in, AuUInt length); template void Read(T(&array)[N]) { ReadSecureRNG(array, N * sizeof(T)); } template void Read(T *array, AuUInt length) { ReadSecureRNG(array, length * sizeof(T)); } enum class RngStringCharacters { eAlphaCharacters, eAlphaNumericCharacters, eExtendedEntropy, MAX }; static void RngString(char *string, AuUInt length, RngStringCharacters type = RngStringCharacters::eAlphaCharacters) { static std::pair rngSequence[static_cast(RngStringCharacters::MAX)] = { {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 52}, {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", 62}, {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890=-+!$%^*.[];:", 75} }; ReadSecureRNG(string, length); const auto &pair = rngSequence[static_cast(type)]; for (auto i = 0; i < length; i++) { auto idx = static_cast(reinterpret_cast(string)[i]) / 255.f * static_cast(pair.second); string[i] = pair.first[static_cast(idx)]; } } }