cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
random.hpp File Reference
#include <algorithm>
#include <chrono>
#include <iterator>
#include <limits>
#include <random>
#include <stdexcept>
#include <vector>
#include <cpp-toolbox/type_traits.hpp>
Include dependency graph for random.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  toolbox::utils::random_t
 随机数工具类/Random number utility class More...
 

Namespaces

namespace  toolbox
 
namespace  toolbox::utils
 < 用于 std::out_of_range/For std::out_of_range
 

Functions

int toolbox::utils::randint (int a, int b)
 生成[a, b]范围内的随机整数/Generate random integer in [a, b]
 
template<typename T >
toolbox::utils::random (T a, T b)
 通用随机数生成函数/General random number generator
 
template<typename T >
toolbox::utils::random ()
 无参数版本的随机数生成函数/Random number generator without parameters
 
template<typename T >
toolbox::utils::uniform (T a, T b)
 生成[a, b]范围内的均匀分布浮点数/Generate uniform random float in [a, b]
 
template<typename T >
toolbox::utils::gauss (T mu, T sigma)
 生成高斯分布(正态分布)随机数/Generate Gaussian (normal) distributed random number
 
template<typename T >
toolbox::utils::choice (const std::vector< T > &vec)
 从vector中随机选择一个元素/Randomly choose one element from vector
 
template<typename T >
std::vector< T > toolbox::utils::choice_n (const std::vector< T > &vec, size_t n)
 从vector中随机选择n个元素/Randomly choose n elements from vector
 
template<typename T >
std::vector< T > toolbox::utils::sample (const std::vector< T > &population, size_t k)
 从vector中随机采样k个元素/Randomly sample k elements from vector
 
template<typename TContainer >
TContainer::value_type toolbox::utils::choice (const TContainer &container)
 通用容器的随机选择/Randomly choose one element from general container
 
template<typename TContainer >
TContainer toolbox::utils::choice_n (const TContainer &container, size_t n)
 通用容器的随机选择n个元素/Randomly choose n elements from general container
 
template<typename TContainer >
TContainer toolbox::utils::sample (const TContainer &container, size_t n)
 通用容器的随机采样n个元素/Randomly sample n elements from general container
 
template<typename TContainer >
void toolbox::utils::shuffle (TContainer &container)
 随机打乱容器/Shuffle the container randomly
 
template<typename TContainer >
TContainer toolbox::utils::generate (std::size_t n, typename TContainer::value_type min, typename TContainer::value_type max)
 生成n个随机数/Generate n random numbers