Created
June 10, 2024 00:06
-
-
Save rodydavis/99d3bd4293746bb9391fff42188149bf to your computer and use it in GitHub Desktop.
ID Generator from the Go codebase
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'; | |
const defaultIdLength = 15; | |
const defaultIdAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789"; | |
String pseudorandomStringWithAlphabet(int length, String alphabet) { | |
final List<int> b = List.filled(length, 0); | |
final int max = alphabet.length; | |
for (int i = 0; i < length; i++) { | |
b[i] = alphabet.codeUnitAt(Random().nextInt(max)); | |
} | |
return String.fromCharCodes(b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment