by @kodeazy

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

Home » flutter » flutter How to get negitive random number between specific range using dart file?
  • In this blog we will discuss on how to get negitive only random number between specific range in flutter.
  • Below is the syntax for getting random number in dart file.

    Random().nextInt(negitiveNumber)-negitiveNumber
  • In the above syntax in place of negitiveNumber we add a number greater than 0.
  • If suppose if we want to print negitive number upto -50 in Random().nextInt(50) we add 50 as parameter so that random number is generated uptill 50 now we subtract the random number by 50 to get the result.
  • Below is the example statement.

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

    import 'dart:math';
    void main() {
    print(Random().nextInt(0 + 50) - 50);
    }

    Output:

    -10