randomSelect的一个小bug

This commit is contained in:
Xu Chang 2023-08-21 11:59:01 +08:00
parent b37e05ac39
commit 002ab66882
2 changed files with 8 additions and 8 deletions

View File

@ -83,10 +83,10 @@ async function select(params, context) {
id: 1,
},
});
const ids = await context.select(entity, idSelection, option || {});
const possibility = count / ids.length;
let reduced = ids.length - count;
const ids2 = ids.filter((id) => {
const idResults = await context.select(entity, idSelection, option || {});
const possibility = count / idResults.length;
let reduced = idResults.length - count;
const ids2 = idResults.map(ele => ele.id).filter((id) => {
const rand = Math.random();
if (rand > possibility && reduced) {
reduced--;

View File

@ -138,15 +138,15 @@ export async function select<
},
});
const ids = await context.select(
const idResults = await context.select(
entity,
idSelection,
option || {}
);
const possibility = count! / ids.length;
let reduced = ids.length - count!;
const ids2 = ids.filter(
const possibility = count! / idResults.length;
let reduced = idResults.length - count!;
const ids2 = idResults.map(ele => ele.id).filter(
(id) => {
const rand = Math.random();
if (rand > possibility && reduced) {