From 36b4d59d5914f1c35f09f82cab65514a48166fa7 Mon Sep 17 00:00:00 2001 From: Krishna Vedala Date: Tue, 26 May 2020 09:05:29 -0400 Subject: [PATCH] `rand_r` is non-portable and obsolete (cherry picked from commit 0ad756f8609efdb5fd3d27508fa692c738fc1fc7) --- math/fast_power.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/math/fast_power.cpp b/math/fast_power.cpp index 4f6e02081..5dd724085 100644 --- a/math/fast_power.cpp +++ b/math/fast_power.cpp @@ -50,30 +50,28 @@ double fast_power_linear(int64_t a, int64_t b) { } int main() { - std::srand(time(NULL)); + std::srand(std::time(nullptr)); std::ios_base::sync_with_stdio(false); std::cout << "Testing..." << std::endl; for (int i = 0; i < 20; i++) { - unsigned int *rand1, *rand2; - int a = rand_r(rand1) % 20 - 10; - int b = rand_r(rand2) % 20 - 10; + int a = std::rand() % 20 - 10; + int b = std::rand() % 20 - 10; std::cout << std::endl << "Calculating " << a << "^" << b << std::endl; assert(fast_power_recursive(a, b) == std::pow(a, b)); assert(fast_power_linear(a, b) == std::pow(a, b)); - std::cout << "------ " << a << "^" << b << " = "<< - fast_power_recursive(a, b) << std::endl; + std::cout << "------ " << a << "^" << b << " = " + << fast_power_recursive(a, b) << std::endl; } int64_t a, b; std::cin >> a >> b; - std::cout << a << "^" << b << " = "<< - fast_power_recursive(a, b) << std::endl; + std::cout << a << "^" << b << " = " << fast_power_recursive(a, b) + << std::endl; - std::cout << a << "^" << b << " = "<< - fast_power_linear(a, b) << std::endl; + std::cout << a << "^" << b << " = " << fast_power_linear(a, b) << std::endl; return 0; }