打乱数组中的内容
目前我用到的是std::shuffle_order_engine.功能是打乱数组中的内容
random功能主要由两个部分组成:generators和distribution(不一定用分布)
generators
a.Pseudo-random(伪随机数) number engines (templates)
b. Engine adaptors
c. 伪随机数引擎(实例化)
d.随机数生成器
distributions
Uniform:
- uniform_int_distribution
- uniform_real_distribution
Related to Bernoulli (yes/no) trials: - bernoulli_distribution
- binomial_distribution
- geometric_distribution
- negative_binomial_distribution
Rate-based distributions: - poisson_distribution
- exponential_distribution
- gamma_distribution
- weibull_distribution
- extreme_value_distribution
Related to Normal distribution: - normal_distribution
- lognormal_distribution
- chi_squared_distribution
- cauchy_distribution
- fisher_f_distribution
- student_t_distribution
Piecewise distributions: - discrete_distribution
- piecewise_constant_distribution
- piecewise_linear_distribution
实例1:
1 | #include <iostream> |
输出:
3 1 3 6 5 2 6 6 1 2
9 8 11 13 9 12 12 9 5 9
实例2:(使用Engine adaptors:shuffle打乱vector顺序)
1 | #include <iostream> |
输出:
9 1 4 6 2 7 0 5 3 8