Last active
July 16, 2023 10:51
-
-
Save IsmailAlamKhan/72c6878d6966e2078bee0098ce734ce6 to your computer and use it in GitHub Desktop.
Random code generate
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
// Generated using Google bard | |
import 'dart:math'; | |
void main() { | |
String passcode = generatePasscode(); | |
print('Generated Passcode: $passcode'); | |
} | |
String generatePasscode({int length = 8, bool useAlphabet = true}) { | |
Random random = Random(); | |
String randomString = ''; | |
for (int i = 0; i < length; i++) { | |
if (useAlphabet) { | |
randomString += String.fromCharCode(random.nextInt(26) + 97); | |
} else { | |
randomString += random.nextInt(10).toString(); | |
} | |
} | |
return randomString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment