Created with <3 with dartpad.dev.
Created
January 29, 2024 08:35
-
-
Save ANNASBlackHat/2398e017752a578c77a7a695be69fdf1 to your computer and use it in GitHub Desktop.
quaint-charm-1968
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