Skip to content

Instantly share code, notes, and snippets.

@xgqfrms
Created July 8, 2020 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgqfrms/9e42e9a14d690037ae8b2207b63f1d61 to your computer and use it in GitHub Desktop.
Save xgqfrms/9e42e9a14d690037ae8b2207b63f1d61 to your computer and use it in GitHub Desktop.
dart:math & Random function
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