by @kodeazy

flutter How to get random number between specific range using dart file?

Home » flutter » 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 than 0.
  • If suppose max value is 50.
  • Above statement gives value betwen 0 to 50.
  • so to get the value between between 50 to 100 we add 50 to the statement.
  • Below is the example statement.

    Random().nextInt(50) + 50
  • In the above statement as we add 50 to the total sum random number is printed between the range of 50 to 100.
  • Blow is an example program to print Random number between 50 to 100.

    import 'dart:math';
    void main() {
    var rand = new Random();
    print(Random().nextInt(50) + 50);
    }

    Output:

    99