Skip to content

Commit 0ad756f

Browse files
committed
rand_r is non-portable and obsolete
1 parent 614ea8e commit 0ad756f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

math/fast_power.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,28 @@ double fast_power_linear(int64_t a, int64_t b) {
5050
}
5151

5252
int main() {
53-
std::srand(time(NULL));
53+
std::srand(std::time(nullptr));
5454
std::ios_base::sync_with_stdio(false);
5555

5656
std::cout << "Testing..." << std::endl;
5757
for (int i = 0; i < 20; i++) {
58-
unsigned int *rand1, *rand2;
59-
int a = rand_r(rand1) % 20 - 10;
60-
int b = rand_r(rand2) % 20 - 10;
58+
int a = std::rand() % 20 - 10;
59+
int b = std::rand() % 20 - 10;
6160
std::cout << std::endl << "Calculating " << a << "^" << b << std::endl;
6261
assert(fast_power_recursive(a, b) == std::pow(a, b));
6362
assert(fast_power_linear(a, b) == std::pow(a, b));
6463

65-
std::cout << "------ " << a << "^" << b << " = "<<
66-
fast_power_recursive(a, b) << std::endl;
64+
std::cout << "------ " << a << "^" << b << " = "
65+
<< fast_power_recursive(a, b) << std::endl;
6766
}
6867

6968
int64_t a, b;
7069
std::cin >> a >> b;
7170

72-
std::cout << a << "^" << b << " = "<<
73-
fast_power_recursive(a, b) << std::endl;
71+
std::cout << a << "^" << b << " = " << fast_power_recursive(a, b)
72+
<< std::endl;
7473

75-
std::cout << a << "^" << b << " = "<<
76-
fast_power_linear(a, b) << std::endl;
74+
std::cout << a << "^" << b << " = " << fast_power_linear(a, b) << std::endl;
7775

7876
return 0;
7977
}

0 commit comments

Comments
 (0)