Generare numeri random in Dart
Generare numeri random in Dart è molto semplice; possiamo usare l'apposita classe Random.
Come potete vedere abbiamo tre metodi:
- nextInt
- nextDouble
- nextBool
Qui sotto un esempio con nextInt:
import 'dart:math';
void main() {
var rng = Random();
for (var i = 0; i < 10; i++) {
print(rng.nextInt(100));
}
}
Al metodo passiamo un parametro, che imposta il range in cui estrapolare il numero.
In questo caso tra 0 e 100.
Enjoy!
dart random nextint nextdouble nextbool
Commentami!