diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index eda60471..a972da47 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -74,9 +74,7 @@ namespace Components auto startTime = std::chrono::high_resolution_clock::now(); bool testRes = component->UnitTest(); auto duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - startTime).count(); - - - Logger::Print("Test done (%llims): %s\n\n", duration, (testRes ? "Success" : "Error"));// + Logger::Print("Test done (%llims): %s\n\n", duration, (testRes ? "Success" : "Error")); result &= testRes; } diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 3a66fa78..d26ecef5 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -766,6 +766,20 @@ namespace Components } printf("Success\n"); + + uint32_t randIntCount = 4'000'000; + printf("Generating %d random integers...", randIntCount); + + auto startTime = std::chrono::high_resolution_clock::now(); + + for (uint32_t i = 0; i < randIntCount; ++i) + { + Utils::Cryptography::Rand::GenerateInt(); + } + + auto duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - startTime).count(); + Logger::Print("took %llims\n", duration); + return true; } } diff --git a/src/Utils/Cryptography.cpp b/src/Utils/Cryptography.cpp index aac08398..2f7d4ace 100644 --- a/src/Utils/Cryptography.cpp +++ b/src/Utils/Cryptography.cpp @@ -10,15 +10,40 @@ namespace Utils uint32_t Rand::GenerateInt() { - size_t length = 0; - uint8_t buffer[4] = { 0 }; + static int length = 0; + static int time = 0; + static int access = 0; + static uint8_t randPool[2048] = { 0 }; - while (length != 4) + int mseconds = Game::Com_Milliseconds(); + + if ((mseconds - time) > (1000 * 60 * 5) || (access > (sizeof(randPool) * 30))) { - length = sprng_read(buffer, sizeof(buffer), NULL); + access = 0; + length = 0; } - return *reinterpret_cast(buffer); + while (length != sizeof(randPool)) + { + length += sprng_read(randPool, sizeof(randPool), NULL); + } + + uint8_t numberBuf[4] = { 0 }; + + for (int i = 0; i < sizeof(numberBuf); ++i) + { + numberBuf[i] = randPool[(rand() + mseconds + i + numberBuf[(i > 0 ? (i - 1) : 0)]) % sizeof(randPool)]; + } + + uint32_t num = *reinterpret_cast(numberBuf); + + if (!(access % 100)) + { + srand(num); + } + + access++; + return num; } #pragma endregion