Created
January 29, 2024 08:35
-
-
Save ANNASBlackHat/9b99c51447d609760859fee7071dc182 to your computer and use it in GitHub Desktop.
Generate Sales Id
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
import 'dart:math'; | |
class Generator { | |
static String generateSalesId() { | |
List<String> words = [ | |
"A", | |
"P", | |
"L", | |
"I", | |
"K", | |
"U", | |
"N", | |
"Q", | |
"D", | |
"E" | |
]; | |
String time = DateTime.now().millisecondsSinceEpoch.toString(); | |
List<String> timeChars = time.split(""); | |
List<int> changes = []; | |
int max = timeChars.length; | |
int min = 1; | |
for (int i = 0; i < timeChars.length ~/ 2; i++) { | |
int index = Random().nextInt(max - min + 1) + min; | |
if (!changes.contains(index)) changes.add(index); | |
} | |
StringBuffer value = StringBuffer(); | |
for (int i = 0; i < timeChars.length; i++) { | |
if (timeChars[i] != '') { | |
if (changes.contains(i)) { | |
value.write(words[int.parse(timeChars[i])]); | |
} else { | |
value.write(timeChars[i]); | |
} | |
} | |
} | |
return value.toString(); | |
} | |
} | |
void main() { | |
print('SalesId: ${Generator.generateSalesId()}'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment