aboutsummaryrefslogtreecommitdiff
path: root/bbot/utility.cxx
blob: 83249adb878252e85e046ef23b9f7c905d96b0a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// file      : bbot/utility.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : TBC; see accompanying LICENSE file

#include <bbot/utility>

#include <chrono>
#include <cstdlib> // rand_r()

#include <bbot/diagnostics>

using namespace std;
using namespace butl;

namespace bbot
{
  static unsigned int rand_seed; // Seed for rand_r();

  size_t
  genrand ()
  {
    if (rand_seed == 0)
      rand_seed = static_cast<unsigned int> (
        chrono::system_clock::now ().time_since_epoch ().count ());

    return static_cast<size_t> (rand_r (&rand_seed));
  }

  void
  run_trace (tracer& t, const char* cmd[], size_t n)
  {
    if (verb >= 3)
    {
      diag_record dr (t);
      process::print (dr.os, cmd, n);
    }
  }
}