VCCC  2024.05
VisualCamp Common C++ library
random

Random algorithms. More...

Detailed Description

Functions

template<typename T , typename Container = std::unordered_set<T>, typename RandomGenerator >
Container pick_k (T a, T b, T k, RandomGenerator &&gen)
 pick k from int range [a, b] (no duplicates) More...
 
template<typename T , typename Container = std::vector<T>>
Container random_sample (T a, T b, T k, std::mt19937 &&gen=std::mt19937(std::random_device{}()))
 get shuffled random sample in [a, b], size k More...
 
template<typename T , typename Container = std::vector<T>, typename Generator >
Container random_sample (T a, T b, T k, Generator &&gen)
 

Function Documentation

◆ pick_k()

Container vccc::pick_k ( a,
b,
k,
RandomGenerator &&  gen 
)

Time complexity is \(O(n)\)

Template Parameters
Ttype
Container= std::unordered_set<T>
Parameters
amin value
bmax value
kpick count
genrandom generator
Returns
container that has picked number

◆ random_sample() [1/2]

Container vccc::random_sample ( a,
b,
k,
Generator &&  gen 
)

◆ random_sample() [2/2]

Container vccc::random_sample ( a,
b,
k,
std::mt19937 &&  gen = std::mt19937(std::random_device{}()) 
)

Time complexity is \(O(n)\)

Template Parameters
Ttype
Containerreturn type
Parameters
amin value
bmax value
ksample size
genrandom generator
Returns
container that has samples