After going through the rabbit hole that is learning about rand() and how it's not very good at generating uniform pseudorandom data based on what I've dug into based on this post: Random float number generation. I am stuck trying to figure out which strategy would yield better balance of performance and accuracy when iterated a significant number of times, 128*10^6 for an example of my use case.
This link is what led me to make this post, otherwise I would have just used rand(): rand() considered harmful
Anyway, my main goal is to figure out how much of a performance difference there is between these two implementations for random number generation, since there doesn't seem to be very good info even on cppreference.com or cplusplus.com for performance or time complexity.
If it turns out that using the generator + distribution approach is not a huge performance hit, I would like to just go with that.
Put simply, what is the time complexity / time performance difference of the following two random number generation strategies and is it always preferable to use the 2nd approach?
- rand()
- std::mt19937 and uniform_real_distribution
Here is an example of what my code would be doing:
int main(){
int numIterations = 128000000;
for(int i = 0; i < numIterations; i++){
rand();
}
}
vs.
#include<random>
int main(){
std::mt19937 mt(1729);
std::uniform_real_distribution<float> dist(0.0, 1.0)
int numIterations = 128000000;
for(int i = 0; i < numIterations; i++){
dist(mt);
}
}
Aucun commentaire:
Enregistrer un commentaire