strRandom method
Implementation
String strRandom([int length = 10]) {
String _chars =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#%^&*()-_=+|[]{};:<>,./?';
final Random _random = Random();
final StringBuffer _buffer = StringBuffer();
for (int i = 0; i < length; i++) {
_buffer.write(_chars[_random.nextInt(_chars.length)]);
}
return _buffer.toString();
// example:
// strRandom(); // returns 'a1B2c3D4e5F6g7H8i9J0k1L2m3N4o5P6q7R8s9T0u1V2w3X4y5Z6'
// strRandom(5); // returns 'a1B2c3D4e5'
}