rng c 2b 2b

Solutions on MaxInterview for rng c 2b 2b by the best coders in the world

showing results for - "rng c 2b 2b"
Reginald
26 Mar 2018
1#include <random> // std::uniform_int_distribution and std::mt19937
2#include <ctime> //time for seed
3#include <iostream>
4// as stroustrup says in a tour of c++ "dont use rand()" its limited
5// mt19937 is way better
6int main(){
7  //this one makes the range, yes its a little ugly
8  std::uniform_int_distribution<int> range(1, 11); 
9  
10  // this one is the engine with seed of time, (why the hell mt19937!!!)
11  std::mt19937 generator(time(nullptr)); 
12  for(int i = 0; i < 5; ++i){
13    //we combine them and baaaam, there we go
14    std::cout << range(generator) << " ";
15  }
16  return 0;
17}
queries leading to this page
cpp rngrng c 2b 2brng c 2b 2b