Created
November 23, 2022 11:32
-
-
Save bannzai/1a99ea9e7d55c9953959162f3710bf19 to your computer and use it in GitHub Desktop.
Dart#randomEmoji
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'; | |
void main() async { | |
print(_randomEmoji()); | |
} | |
String _randomEmoji() { | |
final emojis = _emojis(); | |
return emojis[Random().nextInt(emojis.length - 1)]; | |
} | |
List<String> _emojis() { | |
return _range().map((e) => String.fromCharCode(e)).toList(); | |
} | |
Iterable<int> _range() sync* { | |
const start = 0x1F601; | |
const stop = 0x1F64F; | |
for (int value = start; value < stop; value += 1) { | |
yield value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment