samedi 23 octobre 2021

Using std::random_device can I set a range of floating point numbers but not include certain numbers?

As mentioned in the title I want to generate a random floating-point number between -10 and 10 but I want to make it so that it can't generate a number between -1.99 and 1.99.

My code for randomly generating numbers:

std::random_device random;
std::mt19937 gen(random());
std::uniform_real_distribution<float> dis(-10.0f, 10.0f);

for (int n = 0; n < 10; ++n)
{
    std::cout << dis(gen); << std::endl;
}



Aucun commentaire:

Enregistrer un commentaire