Created
July 8, 2020 07:12
-
-
Save xgqfrms/9e42e9a14d690037ae8b2207b63f1d61 to your computer and use it in GitHub Desktop.
dart:math & Random function
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() { | |
int max = 6; | |
dynamic dice; | |
// int nextInt(int max); | |
dice = Random().nextInt(max); | |
// 0 ~ 5, | |
dice += 1; | |
// 1 ~ 6, | |
print('random dice = ${dice}'); | |
} | |
/// https://api.dart.dev/stable/2.8.4/dart-math/Random/nextInt.html | |
// 生成非负随机整数,其范围从0(包括0)到max(不包括)均匀分布 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://dartpad.dartlang.org/