📜  rng c++ 代码示例

📅  最后修改于: 2022-03-11 14:44:57.194000             🧑  作者: Mango

代码示例1
#include  // std::uniform_int_distribution and std::mt19937
#include  //time for seed
#include 
// as stroustrup says in a tour of c++ "dont use rand()" its limited
// mt19937 is way better
int main(){
  //this one makes the range, yes its a little ugly
  std::uniform_int_distribution range(1, 11); 
  
  // this one is the engine with seed of time, (why the hell mt19937!!!)
  std::mt19937 generator(time(nullptr)); 
  for(int i = 0; i < 5; ++i){
    //we combine them and baaaam, there we go
    std::cout << range(generator) << " ";
  }
  return 0;
}