Created
July 28, 2022 13:20
-
-
Save anhdiepmmk/89165ac9be1696aa7c29fdb5438e7223 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require("lodash"); | |
const fs = require("fs"); | |
const teams = [ | |
{ name: "Phap", weight: 5, rank: 5 }, | |
{ name: "Duc", weight: 3, rank: 5 }, | |
{ name: "Bo dao nha", weight: 2, rank: 5 }, | |
]; | |
const list = _.chain(teams) | |
.flatMap((team) => Array(team.weight).fill(team.name)) | |
.shuffle() | |
.value(); | |
function getRandomTeam() { | |
return _.sample(list); | |
} | |
const reports = []; | |
_.forEach(_.range(1, 1000000 + 1, 1), (idx) => { | |
const name = getRandomTeam(); | |
reports.push({ | |
turn: idx, | |
name, | |
}); | |
}); | |
console.log(reports.length); | |
_.forEach(teams, (team) => { | |
const filteredReports = _.filter( | |
reports, | |
(report) => report.name === team.name | |
); | |
const percent = _.round((filteredReports.length / reports.length) * 100, 2); | |
console.log(team.name, filteredReports.length, `${percent}%`); | |
}); | |
fs.writeFileSync("./report.json", JSON.stringify(reports)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment