std::experimental:: shuffle
From zh.cppreference.net
<
cpp
|
experimental
|
定义于头文件
<experimental/algorithm>
|
||
|
template
<
class
RandomIt
>
void shuffle ( RandomIt first, RandomIt last ) ; |
(库基础 TS v2) | |
对给定范围
[
first
,
last
)
内的元素进行重新排序,使得这些元素的每种可能排列都具有相等的出现概率,使用
每线程随机数引擎
作为随机数生成器。
内容参数
返回值(无) 复杂度与 first 和 last 之间的距离呈线性关系。 示例
运行此代码
#include <experimental/algorithm> #include <iostream> #include <string> int main() { std::string sample{"ABCDEF"}; for (int i = 0; i != 4; ++i) { std::experimental::shuffle(sample.begin(), sample.end()); std::cout << sample << '\n'; } } 可能的输出: DACBFE CDFBAE BDCAFE BAFCED 另请参阅
| |||||||||