在 Visual c + + 中使用 random_shuffle STL 函数
04/24/2020
本文内容
本文介绍如何使用 random_shuffle Visual c + + 中的标准模板库(STL)函数。
原始产品版本: Visual c + +
原始 KB 数: 156994
必需标头
Prototype
template inline
void random_shuffle(RandomAccessIterator first,
RandomAccessIterator last,
Predicate pred)
备注
原型中的类/参数名称与头文件中的原始版本不匹配。 已对其进行修改以提高可读性。
说明
random_shuffle算法 shuffles 序列中的元素(first。最后)的随机顺序。
谓词版本使用 pred 函数生成要交换的元素的索引。 Pred 必须是一个 function 对象,该对象采用参数n ,并返回0到(n-1)范围内的整数随机数字。
用于执行交换的谓词版本 random_shuffle operator= 。
示例代码
//
// Compile options needed: /GX
// random_shuffle.cpp: Illustrates how to use the predicate version
// of the random_shuffle function.
// Functions:
// random_shuffle: Shuffle the elements in a rando