Skip to content

Instantly share code, notes, and snippets.

@klmr
Last active November 3, 2020 21:20
Show Gist options
  • Select an option

  • Save klmr/62863c3d9f5827df23ae2e1415b0cb1b to your computer and use it in GitHub Desktop.

Select an option

Save klmr/62863c3d9f5827df23ae2e1415b0cb1b to your computer and use it in GitHub Desktop.

Revisions

  1. klmr revised this gist Aug 18, 2020. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions rng.cpp
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,14 @@
    #include <algorithm>
    #include <climits>
    #include <array>
    #include <functional>
    #include <limits>
    #include <random>

    template <typename T = std::mt19937>
    auto get_random_generator() -> T {
    auto constexpr seed_bits = sizeof(typename T::result_type) * CHAR_BIT * T::state_size;
    auto constexpr seed_len = seed_bits / std::numeric_limits<std::seed_seq::result_type>::digits;
    auto seed = std::array<std::seed_seq::result_type, seed_len>{};
    auto dev = std::random_device{};
    auto constexpr seed_bytes = sizeof(typename T::result_type) * T::state_size;
    auto constexpr seed_len = seed_bytes / sizeof(std::seed_seq::result_type);
    auto seed = std::array<std::seed_seq::result_type, seed_len>();
    auto dev = std::random_device();
    std::generate_n(begin(seed), seed_len, std::ref(dev));
    auto seed_seq = std::seed_seq(begin(seed), end(seed));
    return T{seed_seq};
  2. klmr revised this gist Aug 18, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion rng.cpp
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,13 @@
    #include <algorithm>
    #include <climits>
    #include <array>
    #include <functional>
    #include <limits>
    #include <random>

    template <typename T = std::mt19937>
    auto get_random_generator() -> T {
    auto constexpr seed_bits = sizeof(typename T::result_type) * T::state_size;
    auto constexpr seed_bits = sizeof(typename T::result_type) * CHAR_BIT * T::state_size;
    auto constexpr seed_len = seed_bits / std::numeric_limits<std::seed_seq::result_type>::digits;
    auto seed = std::array<std::seed_seq::result_type, seed_len>{};
    auto dev = std::random_device{};
  3. klmr created this gist Mar 17, 2020.
    16 changes: 16 additions & 0 deletions rng.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #include <algorithm>
    #include <array>
    #include <functional>
    #include <limits>
    #include <random>

    template <typename T = std::mt19937>
    auto get_random_generator() -> T {
    auto constexpr seed_bits = sizeof(typename T::result_type) * T::state_size;
    auto constexpr seed_len = seed_bits / std::numeric_limits<std::seed_seq::result_type>::digits;
    auto seed = std::array<std::seed_seq::result_type, seed_len>{};
    auto dev = std::random_device{};
    std::generate_n(begin(seed), seed_len, std::ref(dev));
    auto seed_seq = std::seed_seq(begin(seed), end(seed));
    return T{seed_seq};
    }