Skip to content

Instantly share code, notes, and snippets.

@ANNASBlackHat
Created January 29, 2024 08:35
Show Gist options
  • Save ANNASBlackHat/9b99c51447d609760859fee7071dc182 to your computer and use it in GitHub Desktop.
Save ANNASBlackHat/9b99c51447d609760859fee7071dc182 to your computer and use it in GitHub Desktop.
Generate Sales Id
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