by @kodeazy
flutter How to get random number between specific range using dart file?
- In this blog we will discuss on how to get
random
number between specific range in flutter. -
Below is the syntax for getting
random
number in dart file.Random().nextInt(max)
- In the above syntax in place of
max
we add a number greater than0
. - If suppose
max
value is50
. - Above statement gives value betwen
0
to50
. - so to get the value between between
50
to100
we add50
to the statement. -
Below is the example statement.
Random().nextInt(50) + 50
- In the above statement as we add
50
to the totalsum
random number is printed between the range of50
to100
. -
Blow is an example program to print
Random
number between50
to100
.import 'dart:math'; void main() { var rand = new Random(); print(Random().nextInt(50) + 50); }
Output:
99