aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2019-04-20 10:38:59 +0200
committerTom Smeding <tom.smeding@gmail.com>2019-04-20 10:38:59 +0200
commit725f9dec4e7927297938ee99faa5400d9af3be9f (patch)
tree1de0bcc87414d61f0c3d6f1a978c72f27f9e0eba
parent259c0602809c9d4577742a90e4bfcf62f4046e46 (diff)
Use C++ <random> in normal aberth
-rw-r--r--aberth/aberth.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/aberth/aberth.cpp b/aberth/aberth.cpp
index 295e99c..02768e2 100644
--- a/aberth/aberth.cpp
+++ b/aberth/aberth.cpp
@@ -5,12 +5,12 @@
#include <array>
#include <string>
#include <complex>
+#include <random>
#include <utility>
#include <tuple>
#include <algorithm>
#include <thread>
#include <mutex>
-#include <cstdlib>
#include <cstdint>
#include <cassert>
#include "../lodepng.h"
@@ -109,6 +109,8 @@ static double maxRootNorm(const Poly &poly) {
return 1 + value;
}
+static thread_local minstd_rand randgenerator = minstd_rand(random_device()());
+
struct AberthState {
const Poly &poly;
Poly deriv;
@@ -117,7 +119,9 @@ struct AberthState {
double radius;
void regenerate() {
- auto genCoord = [this]() { return (double)random() / INT_MAX * 2 * radius - radius; };
+ auto genCoord = [this]() {
+ return uniform_real_distribution<double>(-radius, radius)(randgenerator);
+ };
for (int i = 0; i < N; i++) {
approx[i] = Com(genCoord(), genCoord());
}
@@ -387,8 +391,6 @@ static vector<int32_t> invoke_kernel(
}
int main(int argc, char **argv) {
- srandomdev();
-
int W, H;
vector<int> counts;