C++ Library Extensions 2022.12.09
To help learn modern C++ programming
tpf::chrono_random Namespace Reference

Implements random number generator and stop watch. More...

Classes

class  fair_dice
 
class  random_t
 
class  random_words
 
class  stop_watch
 

Typedefs

using nano_t = std::nano
 
using micro_t = std::micro
 
using milli_t = std::milli
 
using second_t = std::ratio< 1 >
 
using minute_t = std::ratio< 60 >
 
using hour_t = std::ratio< 3600 >
 
template<typename TimeUnit >
using duration_t = std::chrono::duration< double, TimeUnit >
 
using nanoseconds_t = duration_t< nano_t >
 
using microseconds_t = duration_t< micro_t >
 
using milliseconds_t = duration_t< milli_t >
 
using seconds_t = duration_t< second_t >
 
using minutes_t = duration_t< minute_t >
 
using hours_t = duration_t< hour_t >
 
using high_resolution_clock_t = std::chrono::high_resolution_clock
 
using time_point_t = std::chrono::time_point< high_resolution_clock_t >
 
using random_engine_t = std::default_random_engine
 
template<typename IntegralType , typename Type = std::enable_if_t<types::is_integral_v<IntegralType>>>
using random_uniform_integral_distribution = std::uniform_int_distribution< IntegralType >
 
template<typename RealType , typename Type = std::enable_if_t<types::is_real_number_v<RealType>>>
using random_uniform_real_distribution = std::uniform_real_distribution< RealType >
 
template<typename IntegralType , typename Type = std::enable_if_t<types::is_integral_v<IntegralType>>>
using random_uniform_integer_t = random_t< IntegralType, random_uniform_integral_distribution< IntegralType >, random_engine_t >
 
template<typename RealType , typename Type = std::enable_if_t<types::is_real_number_v<RealType>>>
using random_uniform_real_t = random_t< RealType, random_uniform_real_distribution< RealType >, random_engine_t >
 

Functions

unsigned int seed ()
 
unsigned int get_current_tick ()
 
template<typename TimeUnit >
double time_difference_in_unit (const time_point_t &start_time, const time_point_t &end_time)
 
template<typename ValueType , typename RangeType1 , typename RangeType2 >
auto random_generator (RangeType1 range_start, RangeType2 range_end)
 
template<template< typename, typename... > class ContainerType, typename Type , typename RType , typename... Types, template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void random_fill (ContainerType< Type, Types... > &container, const RandomGeneratorType< RType, RTypes... > &random_generator)
 
template<typename Type , std::size_t N, typename RandomGeneratorType >
void random_fill (Type(&container)[N], RandomGeneratorType const &random_generator)
 
template<typename Type , std::size_t M, std::size_t N, typename RandomGeneratorType >
void random_fill (Type(&container)[M][N], RandomGeneratorType const &random_generator)
 
template<typename Type , std::size_t L, std::size_t M, std::size_t N, typename RandomGeneratorType >
void random_fill (Type(&container)[L][M][N], RandomGeneratorType const &random_generator)
 
template<template< typename, std::size_t > class ContainerType, typename Type , std::size_t N, typename RType , template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void random_fill (ContainerType< Type, N > &container, const RandomGeneratorType< RType, RTypes... > &random_generator)
 
template<template< typename, typename... > class ContainerType, typename Type , typename... Types, typename RandomGeneratorType >
void random_fill (ContainerType< Type, Types... > &container, RandomGeneratorType &&random_generator)
 
template<template< typename, typename... > class ContainerType, typename Type , typename... Types, typename RType , template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void random_parallel_fill (ContainerType< Type, Types... > &container, const RandomGeneratorType< RType, RTypes... > &random_generator)
 
template<typename Type , std::size_t N, template< typename, typename... > class RandomGeneratorType, typename RType , typename... RTypes>
void random_parallel_fill (Type(&container)[N], const RandomGeneratorType< RType, RTypes... > &random_generator)
 
template<typename Type , std::size_t M, std::size_t N, template< typename, typename... > class RandomGeneratorType, typename RType , typename... RTypes>
void random_parallel_fill (Type(&container)[M][N], const RandomGeneratorType< RType, RTypes... > &random_generator)
 
template<typename Type , std::size_t L, std::size_t M, std::size_t N, template< typename, typename... > class RandomGeneratorType, typename RType , typename... RTypes>
void random_parallel_fill (Type(&container)[L][M][N], const RandomGeneratorType< RType, RTypes... > &random_generator)
 
template<template< typename, std::size_t > class ContainerType, typename Type , std::size_t N, typename RType , template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void random_parallel_fill (ContainerType< Type, N > &container, const RandomGeneratorType< RType, RTypes... > &random_generator)
 
template<template< typename, typename... > class ContainerType, typename Type , typename... Types, typename RandomGeneratorType >
void random_parallel_fill (ContainerType< Type, Types... > &container, RandomGeneratorType &&random_generator)
 
template<template< typename, typename... > class ContainerType, typename Type , typename... Types, typename SizeType , template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void random_fill (ContainerType< Type, Types... > &container, const RandomGeneratorType< Type, RTypes... > &random_generator, SizeType size)
 Fills the /a container with random numbers. If the /a container is /a set or /a unordered_set, the range of the random_generator should be sufficiently big, otherwise it can fall into infinity loop.
More...
 
template<typename Type , size_t ArraySize>
 random_words (int, int, int, const Type(&)[ArraySize]) -> random_words< Type, ArraySize >
 

Variables

auto & now = high_resolution_clock_t::now
 

Detailed Description

Implements random number generator and stop watch.

Typedef Documentation

◆ duration_t

template<typename TimeUnit >
using tpf::chrono_random::duration_t = typedef std::chrono::duration<double, TimeUnit>

Definition at line 60 of file tpf_chrono_random.hpp.

◆ high_resolution_clock_t

using tpf::chrono_random::high_resolution_clock_t = typedef std::chrono::high_resolution_clock

Definition at line 69 of file tpf_chrono_random.hpp.

◆ hour_t

using tpf::chrono_random::hour_t = typedef std::ratio<3600>

Definition at line 57 of file tpf_chrono_random.hpp.

◆ hours_t

Definition at line 67 of file tpf_chrono_random.hpp.

◆ micro_t

using tpf::chrono_random::micro_t = typedef std::micro

Definition at line 53 of file tpf_chrono_random.hpp.

◆ microseconds_t

Definition at line 63 of file tpf_chrono_random.hpp.

◆ milli_t

using tpf::chrono_random::milli_t = typedef std::milli

Definition at line 54 of file tpf_chrono_random.hpp.

◆ milliseconds_t

Definition at line 64 of file tpf_chrono_random.hpp.

◆ minute_t

using tpf::chrono_random::minute_t = typedef std::ratio<60>

Definition at line 56 of file tpf_chrono_random.hpp.

◆ minutes_t

Definition at line 66 of file tpf_chrono_random.hpp.

◆ nano_t

using tpf::chrono_random::nano_t = typedef std::nano

Definition at line 52 of file tpf_chrono_random.hpp.

◆ nanoseconds_t

Definition at line 62 of file tpf_chrono_random.hpp.

◆ random_engine_t

using tpf::chrono_random::random_engine_t = typedef std::default_random_engine

Definition at line 112 of file tpf_chrono_random.hpp.

◆ random_uniform_integer_t

template<typename IntegralType , typename Type = std::enable_if_t<types::is_integral_v<IntegralType>>>
using tpf::chrono_random::random_uniform_integer_t = typedef random_t<IntegralType, random_uniform_integral_distribution<IntegralType>, random_engine_t>

Definition at line 260 of file tpf_chrono_random.hpp.

◆ random_uniform_integral_distribution

template<typename IntegralType , typename Type = std::enable_if_t<types::is_integral_v<IntegralType>>>
using tpf::chrono_random::random_uniform_integral_distribution = typedef std::uniform_int_distribution<IntegralType>

Definition at line 116 of file tpf_chrono_random.hpp.

◆ random_uniform_real_distribution

template<typename RealType , typename Type = std::enable_if_t<types::is_real_number_v<RealType>>>
using tpf::chrono_random::random_uniform_real_distribution = typedef std::uniform_real_distribution<RealType>

Definition at line 121 of file tpf_chrono_random.hpp.

◆ random_uniform_real_t

template<typename RealType , typename Type = std::enable_if_t<types::is_real_number_v<RealType>>>
using tpf::chrono_random::random_uniform_real_t = typedef random_t<RealType, random_uniform_real_distribution<RealType>, random_engine_t>

Definition at line 265 of file tpf_chrono_random.hpp.

◆ second_t

using tpf::chrono_random::second_t = typedef std::ratio<1>

Definition at line 55 of file tpf_chrono_random.hpp.

◆ seconds_t

Definition at line 65 of file tpf_chrono_random.hpp.

◆ time_point_t

using tpf::chrono_random::time_point_t = typedef std::chrono::time_point<high_resolution_clock_t>

Definition at line 70 of file tpf_chrono_random.hpp.

Function Documentation

◆ get_current_tick()

unsigned int tpf::chrono_random::get_current_tick ( )

Definition at line 77 of file tpf_chrono_random.hpp.

◆ random_fill() [1/7]

template<template< typename, std::size_t > class ContainerType, typename Type , std::size_t N, typename RType , template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void tpf::chrono_random::random_fill ( ContainerType< Type, N > &  container,
const RandomGeneratorType< RType, RTypes... > &  random_generator 
)

Definition at line 387 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_fill() [2/7]

template<template< typename, typename... > class ContainerType, typename Type , typename RType , typename... Types, template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void tpf::chrono_random::random_fill ( ContainerType< Type, Types... > &  container,
const RandomGeneratorType< RType, RTypes... > &  random_generator 
)

Definition at line 349 of file tpf_chrono_random.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ random_fill() [3/7]

template<template< typename, typename... > class ContainerType, typename Type , typename... Types, typename SizeType , template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void tpf::chrono_random::random_fill ( ContainerType< Type, Types... > &  container,
const RandomGeneratorType< Type, RTypes... > &  random_generator,
SizeType  size 
)

Fills the /a container with random numbers. If the /a container is /a set or /a unordered_set, the range of the random_generator should be sufficiently big, otherwise it can fall into infinity loop.

Template Parameters
ContainerType
Type
Types
SizeType
RandomGeneratorType
RTypes
Parameters
container
random_generator
size

Definition at line 596 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_fill() [4/7]

template<template< typename, typename... > class ContainerType, typename Type , typename... Types, typename RandomGeneratorType >
void tpf::chrono_random::random_fill ( ContainerType< Type, Types... > &  container,
RandomGeneratorType &&  random_generator 
)

Definition at line 399 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_fill() [5/7]

template<typename Type , std::size_t L, std::size_t M, std::size_t N, typename RandomGeneratorType >
void tpf::chrono_random::random_fill ( Type(&)  container[L][M][N],
RandomGeneratorType const &  random_generator 
)

Definition at line 376 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_fill() [6/7]

template<typename Type , std::size_t M, std::size_t N, typename RandomGeneratorType >
void tpf::chrono_random::random_fill ( Type(&)  container[M][N],
RandomGeneratorType const &  random_generator 
)

Definition at line 367 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_fill() [7/7]

template<typename Type , std::size_t N, typename RandomGeneratorType >
void tpf::chrono_random::random_fill ( Type(&)  container[N],
RandomGeneratorType const &  random_generator 
)

Definition at line 360 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_generator()

template<typename ValueType , typename RangeType1 , typename RangeType2 >
auto tpf::chrono_random::random_generator ( RangeType1  range_start,
RangeType2  range_end 
)

Definition at line 269 of file tpf_chrono_random.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ random_parallel_fill() [1/6]

template<template< typename, std::size_t > class ContainerType, typename Type , std::size_t N, typename RType , template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void tpf::chrono_random::random_parallel_fill ( ContainerType< Type, N > &  container,
const RandomGeneratorType< RType, RTypes... > &  random_generator 
)

Definition at line 506 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_parallel_fill() [2/6]

template<template< typename, typename... > class ContainerType, typename Type , typename... Types, typename RType , template< typename, typename... > class RandomGeneratorType, typename... RTypes>
void tpf::chrono_random::random_parallel_fill ( ContainerType< Type, Types... > &  container,
const RandomGeneratorType< RType, RTypes... > &  random_generator 
)

Definition at line 412 of file tpf_chrono_random.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ random_parallel_fill() [3/6]

template<template< typename, typename... > class ContainerType, typename Type , typename... Types, typename RandomGeneratorType >
void tpf::chrono_random::random_parallel_fill ( ContainerType< Type, Types... > &  container,
RandomGeneratorType &&  random_generator 
)

Definition at line 543 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_parallel_fill() [4/6]

template<typename Type , std::size_t L, std::size_t M, std::size_t N, template< typename, typename... > class RandomGeneratorType, typename RType , typename... RTypes>
void tpf::chrono_random::random_parallel_fill ( Type(&)  container[L][M][N],
const RandomGeneratorType< RType, RTypes... > &  random_generator 
)

Definition at line 493 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_parallel_fill() [5/6]

template<typename Type , std::size_t M, std::size_t N, template< typename, typename... > class RandomGeneratorType, typename RType , typename... RTypes>
void tpf::chrono_random::random_parallel_fill ( Type(&)  container[M][N],
const RandomGeneratorType< RType, RTypes... > &  random_generator 
)

Definition at line 482 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_parallel_fill() [6/6]

template<typename Type , std::size_t N, template< typename, typename... > class RandomGeneratorType, typename RType , typename... RTypes>
void tpf::chrono_random::random_parallel_fill ( Type(&)  container[N],
const RandomGeneratorType< RType, RTypes... > &  random_generator 
)

Definition at line 448 of file tpf_chrono_random.hpp.

Here is the call graph for this function:

◆ random_words()

template<typename Type , size_t ArraySize>
tpf::chrono_random::random_words ( int  ,
int  ,
int  ,
const   Type(&)[ArraySize] 
) -> random_words< Type, ArraySize >

◆ seed()

unsigned int tpf::chrono_random::seed ( )
inline

Definition at line 73 of file tpf_chrono_random.hpp.

Here is the caller graph for this function:

◆ time_difference_in_unit()

template<typename TimeUnit >
double tpf::chrono_random::time_difference_in_unit ( const time_point_t start_time,
const time_point_t end_time 
)

Definition at line 90 of file tpf_chrono_random.hpp.

Variable Documentation

◆ now

auto& tpf::chrono_random::now = high_resolution_clock_t::now

Definition at line 71 of file tpf_chrono_random.hpp.