Created
September 16, 2024 05:06
-
-
Save arunrreddy/92021cd7fbdf32e64bcfb1266685b1ca to your computer and use it in GitHub Desktop.
Coupon code generator
This file contains hidden or 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 fs = require('fs'); | |
| const pattern = /^MT[A-Z0-9]{7}$/; | |
| const codeCount = 1000000; | |
| const outputFile = 'codes_5.csv'; | |
| const codes = []; | |
| const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | |
| const charsetLength = charset.length; | |
| while (codes.length < codeCount) { | |
| let code = 'MT'; | |
| for (let i = 0; i < 7; i++) { | |
| code += charset.charAt(Math.floor(Math.random() * charsetLength)); | |
| } | |
| if (pattern.test(code)) { | |
| codes.push(code); | |
| } | |
| } | |
| // Convert the codes to a CSV string | |
| const csvContent = 'Code\n' + codes.join('\n'); | |
| // Save the generated codes to a CSV file | |
| fs.writeFileSync(outputFile, csvContent, 'utf8'); | |
| console.log(`Generated ${codes.length} unique codes and saved them to '${outputFile}'.`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment