File: random_int.cpp

package info (click to toggle)
simdutf 7.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,244 kB
  • sloc: cpp: 60,074; ansic: 14,226; python: 3,364; sh: 321; makefile: 12
file content (32 lines) | stat: -rw-r--r-- 843 bytes parent folder | download
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
#include "random_int.h"

#include <stdexcept>

namespace simdutf {
namespace tests {
namespace helpers {

RandomInt::RandomInt(uint64_t lo, uint64_t hi, uint64_t seed) noexcept
    : gen(std::mt19937::result_type(seed)), distr{lo, hi} {}

uint32_t RandomInt::operator()() noexcept { return uint32_t(distr(gen)); }

RandomIntRanges::RandomIntRanges(
    std::initializer_list<std::pair<uint64_t, uint64_t>> ranges_,
    uint64_t seed) noexcept
    : gen(std::mt19937::result_type(seed)) {

  for (const auto &lohi : ranges_) {
    ranges.emplace_back(lohi.first, lohi.second);
  }

  range_index = Distribution(0, ranges.size() - 1);
}

uint32_t RandomIntRanges::operator()() noexcept {
  const size_t index = size_t(range_index(gen));
  return uint32_t(ranges[index](gen));
}
} // namespace helpers
} // namespace tests
} // namespace simdutf