dasdasd
This commit is contained in:
parent
3308b7d1d0
commit
1382ebd104
@ -143,12 +143,12 @@ export class CardGeneratorTool extends BaseTool<CardGeneratorConfig> {
|
||||
const rand = Math.random();
|
||||
|
||||
if (rand < 0.5) {
|
||||
// 50% 权重生成(严格按照70张成功案例的统计规律)
|
||||
// 50% 马尔可夫链生成(考虑位置关联性)
|
||||
return this.generateByWeights(selectedPrefix, digitsNeeded, length);
|
||||
}
|
||||
if (rand < 0.9) {
|
||||
// 40% 变异生成(从成功案例变异1-2位)
|
||||
return this.generateByMutation(selectedPrefix, successfulPatterns || [], generation.mutationDigits || [1, 1], digitsNeeded, length);
|
||||
return this.generateByMutation(selectedPrefix, successfulPatterns || [], generation?.mutationDigits || [1, 1], digitsNeeded, length);
|
||||
}
|
||||
// 10% 纯随机(保持多样性)
|
||||
}
|
||||
@ -280,7 +280,7 @@ export class CardGeneratorTool extends BaseTool<CardGeneratorConfig> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于统计权重生成卡号(60个成功案例的分布)
|
||||
* 基于马尔可夫链生成卡号(考虑位置之间的关联性)
|
||||
* @param {string} prefix - BIN前缀
|
||||
* @param {number} digitsNeeded - 需要生成的主体位数(不含校验位)
|
||||
* @param {number} totalLength - 卡号总长度
|
||||
@ -291,23 +291,33 @@ export class CardGeneratorTool extends BaseTool<CardGeneratorConfig> {
|
||||
return generateLuhnNumber(prefix, totalLength);
|
||||
}
|
||||
|
||||
// 基于70个真实成功案例的位置权重(后2位,不含校验位)
|
||||
const positionWeights = [
|
||||
[12, 7, 10, 7, 8, 5, 5, 9, 6, 1], // 百位: 0占17.1%
|
||||
[9, 7, 8, 3, 6, 7, 3, 10, 9, 8] // 十位: 7占14.3%
|
||||
];
|
||||
|
||||
if (digitsNeeded > positionWeights.length) {
|
||||
if (digitsNeeded !== 2) {
|
||||
// 如果不是2位,降级到纯随机
|
||||
return generateLuhnNumber(prefix, totalLength);
|
||||
}
|
||||
|
||||
let pattern = '';
|
||||
for (let pos = 0; pos < digitsNeeded; pos++) {
|
||||
const weights = positionWeights[pos];
|
||||
const digit = this.weightedRandomDigit(weights);
|
||||
pattern += digit;
|
||||
}
|
||||
|
||||
// 第1位:百位的权重分布
|
||||
const firstDigitWeights = [12, 7, 10, 7, 8, 5, 5, 9, 6, 1];
|
||||
const firstDigit = this.weightedRandomDigit(firstDigitWeights);
|
||||
|
||||
// 第2位:基于第1位的马尔可夫转移概率
|
||||
const markovTransitions: Record<string, number[]> = {
|
||||
'0': [3, 1, 1, 2, 0, 2, 1, 2, 0, 0],
|
||||
'1': [0, 0, 2, 0, 1, 2, 0, 2, 0, 0],
|
||||
'2': [2, 0, 0, 0, 1, 2, 0, 1, 4, 0],
|
||||
'3': [0, 2, 2, 0, 0, 0, 1, 2, 0, 0],
|
||||
'4': [1, 0, 1, 0, 3, 0, 0, 1, 1, 1],
|
||||
'5': [0, 3, 1, 0, 0, 0, 0, 0, 1, 0],
|
||||
'6': [1, 0, 0, 0, 1, 0, 0, 1, 1, 1],
|
||||
'7': [1, 1, 1, 1, 0, 0, 1, 0, 2, 2],
|
||||
'8': [1, 0, 0, 0, 0, 1, 0, 1, 0, 3],
|
||||
'9': [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
|
||||
};
|
||||
|
||||
const secondDigitWeights = markovTransitions[firstDigit] || [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
|
||||
const secondDigit = this.weightedRandomDigit(secondDigitWeights);
|
||||
|
||||
const pattern = firstDigit + secondDigit;
|
||||
const partial = prefix + pattern;
|
||||
const checkDigit = this.calculateLuhnCheckDigit(partial);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user