vendredi 24 avril 2020

While looping random seed until desired coordinates are met

In C++ I want to generate random seeds using a while loop until the desired coordinates are met. I'm not sure where to start or what angle to use. Here is the code that I'm working with.

#include <iostream>
#include <random>

int main() {
    std::cout << "Enter seed: ";

    std::string ss;
    std::cin >> ss;

    // Hash seed to 4 byte int
    const int hashConst = 111337;

    unsigned int hash = 0;
    for( size_t i = 0; i < ss.length(); ++i ) {
        hash ^= ss[i];
        hash *= hashConst;
    }

    std::seed_seq ssq { hash };
    std::mt19937_64 mt { ssq };

    std::uniform_int_distribution<int> dist( -10000/2, 10000/2 );

    std::cout << dist(mt) << ", " << dist(mt) << std::endl;
}



Aucun commentaire:

Enregistrer un commentaire