Answer to Question #210202 in C++ for Annie

Question #210202

Print a random number Between 1 and 75 inclusive


1
Expert's answer
2021-06-24T07:36:12-0400


#include <random>
#include <iostream>

int main()
{
    // Create a random device and use it to generate a random seed
    std::random_device myRandomDevice;
    unsigned seed = myRandomDevice();
    
    // Initialize a default_random_engine with the seed
    std::default_random_engine myRandomEngine(seed);
    
    // Initialize a uniform_int_distribution to produce values between 1 and 75
    std::uniform_int_distribution<int> myUnifIntDist(1, 75);
    
    std::cout << myUnifIntDist(myRandomEngine) << " " << std::endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS