Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

rng c++

#include <random> // std::uniform_int_distribution and std::mt19937
#include <ctime> //time for seed
#include <iostream>
// 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<int> 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;
}
 
PREVIOUS NEXT
Tagged: #rng
ADD COMMENT
Topic
Name
9+4 =