Tsallaka zuwa abun ciki
Justice Tech School

chrono and random

<random> makes good random numbers and <chrono> measures time.

Example
#include <iostream>
#include <random>
#include <chrono>

int main() {
  std::mt19937 rng(42);
  std::uniform_int_distribution<int> d(1, 6);
  int r = d(rng);
  std::cout << (r >= 1 && r <= 6) << "\n";
  auto t = std::chrono::steady_clock::now();
  std::cout << (t.time_since_epoch().count() > 0) << "\n";
  return 0;
}

Result

1
1

Exercise

Random engine.

std:: rng(42);

Quiz Test

Why seed an engine?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.