feat:更新core 和首页代码

This commit is contained in:
R524809
2026-03-27 17:31:52 +08:00
parent dc5e057cb3
commit 1b45ba7d11
44 changed files with 2891 additions and 1087 deletions
+13 -4
View File
@@ -13,11 +13,20 @@ export function randomPick<T>(arr: T[]): T {
}
/**
* 从数组中随机选取 n 个不重复元素
* 从数组中随机选取 n 个不重复元素Fisher-Yates,无 sort 偏置)
*/
export function randomPickN<T>(arr: T[], n: number): T[] {
const shuffled = [...arr].sort(() => Math.random() - 0.5);
return shuffled.slice(0, Math.min(n, arr.length));
export function randomPickN<T>(arr: readonly T[], n: number): T[] {
return sampleWithoutReplacement(arr, n);
}
/**
* 无放回抽样,不改变入参数组
*/
export function sampleWithoutReplacement<T>(
arr: readonly T[],
n: number,
): T[] {
return shuffle([...arr]).slice(0, Math.min(n, arr.length));
}
/**