random.hpp

Created 2025-08-18T09:47:34.247Z, last edited 2025-08-18T09:52:57.824Z

 6
 7
 8
 9
10
11
12
13
#pragma once


#include <random>


inline thread_local std::random_device device;
inline thread_local std::mt19937 generator(device());

Pick a number between zero and less than upto

17
18
19
inline std::size_t pick_index(std::size_t const upto) {
    return std::uniform_int_distribution<std::size_t>{0, upto - 1}(generator);
}

Linear random number between ±1

23
24
25
inline float random_weight() {
    return std::uniform_real_distribution<float>{-1.0f, 1.0f}(generator);
}