RandX 1.4.3
基于 xoshiro/xoroshiro 算法族的纯头文件伪随机数生成器库
载入中...
搜索中...
未找到
容器操作

RandElement / RandSample / RandShuffle / RandPermutation / RandFill / RandVector 更多...

函数

template<class Container>
requires std::ranges::random_access_range<Container>
decltype(auto) RandX::RandElement (Container &c)
 从容器中随机取一个元素(左值容器,返回引用)
template<class Container>
requires std::ranges::random_access_range<Container>
std::ranges::range_value_t< Container > RandX::RandElement (Container &&c)
 从容器中随机取一个元素(右值容器,按值返回以避免悬垂引用)
template<std::random_access_iterator It>
It RandX::RandElement (It first, It last)
 从迭代器范围内随机取一个元素(随机访问迭代器:O(1) 直接定位)
template<std::random_access_iterator It, class Engine>
It RandX::RandElement (Engine &engine, It first, It last)
 从迭代器范围内随机取一个元素(指定引擎,随机访问迭代器)

详细描述

RandElement / RandSample / RandShuffle / RandPermutation / RandFill / RandVector

函数说明

◆ RandElement() [1/4]

template<class Container>
requires std::ranges::random_access_range<Container>
std::ranges::range_value_t< Container > RandX::RandElement ( Container && c)
inlinenodiscard

从容器中随机取一个元素(右值容器,按值返回以避免悬垂引用)

参数
c源容器(需支持 operator[] 和 size())
返回
容器中随机选取的一个元素的副本
异常
std::invalid_argument容器为空时抛出
函数调用图:

◆ RandElement() [2/4]

template<class Container>
requires std::ranges::random_access_range<Container>
decltype(auto) RandX::RandElement ( Container & c)
inlinenodiscard

从容器中随机取一个元素(左值容器,返回引用)

参数
c源容器(需支持 operator[] 和 size())
返回
容器中随机选取的一个元素的引用
异常
std::invalid_argument容器为空时抛出
函数调用图:

◆ RandElement() [3/4]

template<std::random_access_iterator It, class Engine>
It RandX::RandElement ( Engine & engine,
It first,
It last )
inlinenodiscard

从迭代器范围内随机取一个元素(指定引擎,随机访问迭代器)

参数
engine自定义随机数引擎
first范围起始迭代器
last范围结束迭代器
返回
指向随机选取元素的迭代器
函数调用图:

◆ RandElement() [4/4]

template<std::random_access_iterator It>
It RandX::RandElement ( It first,
It last )
inlinenodiscard

从迭代器范围内随机取一个元素(随机访问迭代器:O(1) 直接定位)

参数
first范围起始迭代器
last范围结束迭代器
返回
指向随机选取元素的迭代器
异常
std::invalid_argument范围为空时抛出
函数调用图: