jeudi 30 décembre 2021

Multithreading in c++ as a random number generator

I was reading up on multithreading in c++ and found out that if you'd run code like

#include <isostream>
#include <thread>

void function1(){
    for(int i = 0; i<200; i++){
        std::cout << '+';
    }
}
void function2(){
    for(int i = 0; i<200; i++){
        std::cout << '-';
    }
}
int main() {
    std::thread worker1(function1);
    std::thread worker2(function2);
    
    system("pause>nul");
}

The plusses and minusses are in random order as this is dependent on what thread is finishing first, my question is then if this form of racing between threads could be a good random number generator and why (not).
Thanks in advance




Aucun commentaire:

Enregistrer un commentaire