How to generate a random number in C++?

后端 未结 11 1568
萌比男神i
萌比男神i 2020-11-22 11:14

I\'m trying to make a game with dice, and I need to have random numbers in it (to simulate the sides of the die. I know how to make it between 1 and 6). Using



        
11条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 12:02

    for random every RUN file

    size_t randomGenerator(size_t min, size_t max) {
        std::mt19937 rng;
        rng.seed(std::random_device()());
        //rng.seed(std::chrono::high_resolution_clock::now().time_since_epoch().count());
        std::uniform_int_distribution dist(min, max);
    
        return dist(rng);
    }
    

提交回复
热议问题