modularity
This commit is contained in:
@ -40,23 +40,10 @@ const TEMPLATES: Template[] = [
|
||||
{ pattern: "((t>>S1)|(t>>S2))&((t>>S3)|(t>>S4))", weight: 6 }
|
||||
]
|
||||
|
||||
const TOTAL_WEIGHT = TEMPLATES.reduce((sum, t) => sum + t.weight, 0)
|
||||
|
||||
function randomElement<T>(arr: T[]): T {
|
||||
return arr[Math.floor(Math.random() * arr.length)]
|
||||
}
|
||||
|
||||
function pickTemplate(): Template {
|
||||
let random = Math.random() * TOTAL_WEIGHT
|
||||
for (const template of TEMPLATES) {
|
||||
random -= template.weight
|
||||
if (random <= 0) {
|
||||
return template
|
||||
}
|
||||
}
|
||||
return TEMPLATES[0]
|
||||
}
|
||||
|
||||
function fillTemplate(pattern: string): string {
|
||||
let formula = pattern
|
||||
|
||||
|
||||
Reference in New Issue
Block a user