in my project i have shipments, I want to generate a random number of 15 digits to be used to track. How to achieve that?
Asked
Active
Viewed 850 times
3 Answers
0
Try below code hope its helpful to you. refer Random
here
import 'dart:math';
main(){
var number ="";
var randomnumber= Random();
//chnage i < 15 on your digits need
for (var i = 0; i < 15; i++) {
number = number + randomnumber.nextInt(9).toString();
}
print(number);
}
Your output : 353572614254280

Ravindra S. Patil
- 11,757
- 3
- 13
- 40
0
import 'dart:math';
Random random = new Random();
int rNumber = random.nextInt(10^15); // 15 digits (0 to 999999999999999)
int rNumber2 = random.nextInt(10^15) + 10^14; // 100000000000000 to 999999999999999

Maikzen
- 1,504
- 2
- 6
- 18
0
Well I don't know if there is any "optimal" way to do that but you can try the following using math library of dart.
String generate15Digits(){
var rng = Random();
String generatedNumber = '';
for(int i=0;i<15;i++){
generatedNumber += (rng.nextInt(9)+1).toString();
}
return generatedNumber;
}
Also do keep in mind that the first digit will never be zero (because we are adding 1 to every digit), and you need to add import 'dart:math'
library

TolgaT
- 175
- 2
- 7