Console Library 8.0.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
console::gen::Random< T > Class Template Reference

随机数生成器,生成指定范围内的随机数。 More...

#include <gextra.h>

Inheritance diagram for console::gen::Random< T >:
console::Generator< Random< T >, T >

Public Member Functions

 Random (T min, T max, std::mt19937::result_type seed=std::random_device{}())
 构造函数。
bool done ()
 检查生成器是否已完成。
T current ()
 获取当前随机数。
void advance ()
 向前移动一步。
Public Member Functions inherited from console::Generator< Random< T >, T >
iterator iter () const
 获取生成器的迭代器对象。
iterator begin () const
 获取开始迭代器。
iterator end () const
 获取结束迭代器。
bool done ()
 检查生成器是否已完成。
T current ()
 获取当前值。
void advance ()
 推进生成器到下一个位置。

Private Attributes

std::mt19937 gen_
uniform_distribution_t< T > dist_
T curr_

Additional Inherited Members

Public Types inherited from console::Generator< Random< T >, T >
typedef T value_type
 生成器产生的值类型。

Detailed Description

template<class T>
class console::gen::Random< T >

随机数生成器,生成指定范围内的随机数。

Template Parameters
T数值类型。

Constructor & Destructor Documentation

◆ Random()

template<class T>
console::gen::Random< T >::Random ( T min,
T max,
std::mt19937::result_type seed = std::random_device{}() )
inline

构造函数。

Parameters
min随机数最小值(包含)。
max随机数最大值(包含)。
seed随机数种子,默认为随机设备生成。

Member Function Documentation

◆ advance()

template<class T>
void console::gen::Random< T >::advance ( )
inline

向前移动一步。

◆ current()

template<class T>
T console::gen::Random< T >::current ( )
inline

获取当前随机数。

Returns
生成的随机数。

◆ done()

template<class T>
bool console::gen::Random< T >::done ( )
inline

检查生成器是否已完成。

Returns
始终返回false(无限生成)。

Member Data Documentation

◆ curr_

template<class T>
T console::gen::Random< T >::curr_
private

◆ dist_

template<class T>
uniform_distribution_t<T> console::gen::Random< T >::dist_
private

◆ gen_

template<class T>
std::mt19937 console::gen::Random< T >::gen_
private

The documentation for this class was generated from the following file: