an example of using C++ default_random_engine, which is a function object class

compared with a simple C library function named rand



👍 g++ randoms.cpp && ./a.out
48271 182605794 1291394886 
16807 282475249 1622650073 
👍 g++ randoms.cpp && ./a.out
48271 182605794 1291394886 
16807 282475249 1622650073 
👍 cat randoms.cpp 
#include <iostream>
#include <random>
using namespace std;

int main() {
  default_random_engine e;
  for (size_t i = 0; i < 3; ++i)
    cout << e() << ' ';
  cout << endl;

  for (size_t i = 0; i < 3; ++i)
    cout << rand() << ' ';
  cout << endl;
}