pub fn shuffle<T, U>(table: U) -> UAvailable on crate feature
rand only.Expand description
使用系统熵打乱序列,并将所有权返回给调用者。
基于 Fisher–Yates 洗牌(见 shuffle_with,索引选取采用 Lemire 无偏约减),熵源取自 next;
空序列与单元素序列保持不变。
§Feature Requirement
需要启用 "rand" 特性。
§Examples
use lib_unknown::rand::shuffle;
let v = shuffle([0, 1, 2, 3, 4, 5, 6, 7]);
assert_eq!(v.len(), 8);
// 洗牌是原序列的一个置换:排序后应与原序列一致。
let mut sorted = v;
sorted.sort_unstable();
assert_eq!(sorted, [0, 1, 2, 3, 4, 5, 6, 7]);