samedi 3 juillet 2021

C++ std::uniform_int_distribution only generating 0-9 even when chaning params

When I run this function to fill a vector using random unsigned shorts from 5-20, it will instead fill it with numbers 0-9. Even when I change it to another number x-y the problem still persists. I must be doing something wrong, but I've been searching, have changed my seed, used something other than std::mt19937 for the engine, but it doesn't help. toFill will only contain numbers 0-9;

 void pageFaultSim::generateRandomVector(std::vector<unsigned short>& toFill)   {
        std::random_device rd;
        std::mt19937 mtGen(rd());
        std::uniform_int_distribution<unsigned short> dist(5, 20);
    
        auto gen = [&dist, &mtGen](){
            return dist(mtGen);
        };
    
        std::ranges::generate(toFill, gen);
    }



Aucun commentaire:

Enregistrer un commentaire