Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Created June 10, 2024 00:06
Show Gist options
  • Save rodydavis/99d3bd4293746bb9391fff42188149bf to your computer and use it in GitHub Desktop.
Save rodydavis/99d3bd4293746bb9391fff42188149bf to your computer and use it in GitHub Desktop.
ID Generator from the Go codebase
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