auto-account-machine/browser-automation-ts/test-gen.mjs
2025-11-27 10:34:59 +08:00

75 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 测试卡号生成规律
*/
import pkg from './src/tools/card/CardGeneratorTool.js';
const { CardGeneratorTool } = pkg;
async function test() {
console.log('开始生成1000张卡...\n');
const cardGen = new CardGeneratorTool();
await cardGen.initialize({});
const cards = await cardGen.generateBatch(1000, 'unionpay');
// 统计后4位的分布
const pos1 = {};
const pos2 = {};
const pos3 = {};
cards.forEach(card => {
const last4 = card.number.slice(-4);
const digits = last4.slice(0, 3);
pos1[digits[0]] = (pos1[digits[0]] || 0) + 1;
pos2[digits[1]] = (pos2[digits[1]] || 0) + 1;
pos3[digits[2]] = (pos3[digits[2]] || 0) + 1;
});
console.log('=== 生成的1000张卡的数字分布 ===\n');
console.log('位置1千位频率:');
for (let i = 0; i <= 9; i++) {
const count = pos1[i] || 0;
const percent = (count / 1000 * 100).toFixed(1);
const expected = [14, 9, 7, 8, 10, 2, 4, 7, 7, 2][i];
const expectedPercent = (expected / 70 * 100).toFixed(1);
console.log(` ${i}: ${count}次 (${percent}%) [期望: ${expectedPercent}%]`);
}
console.log('\n位置2百位频率:');
for (let i = 0; i <= 9; i++) {
const count = pos2[i] || 0;
const percent = (count / 1000 * 100).toFixed(1);
const expected = [10, 7, 10, 2, 5, 8, 2, 11, 8, 7][i];
const expectedPercent = (expected / 70 * 100).toFixed(1);
console.log(` ${i}: ${count}次 (${percent}%) [期望: ${expectedPercent}%]`);
}
console.log('\n位置3十位频率:');
for (let i = 0; i <= 9; i++) {
const count = pos3[i] || 0;
const percent = (count / 1000 * 100).toFixed(1);
const expected = [10, 2, 4, 11, 8, 9, 6, 6, 7, 7][i];
const expectedPercent = (expected / 70 * 100).toFixed(1);
console.log(` ${i}: ${count}次 (${percent}%) [期望: ${expectedPercent}%]`);
}
console.log('\n=== 前20张生成的卡号 ===\n');
cards.slice(0, 20).forEach((card, i) => {
const last4 = card.number.slice(-4);
console.log(`${i + 1}. ${card.number} (后4位: ${last4})`);
});
const uniqueNumbers = new Set(cards.map(c => c.number));
console.log(`\n=== 去重检查 ===`);
console.log(`生成: 1000张`);
console.log(`唯一: ${uniqueNumbers.size}`);
console.log(`重复: ${1000 - uniqueNumbers.size}`);
}
test().catch(err => {
console.error('错误:', err.message);
console.error(err.stack);
});