Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,623 questions

55,358 answers

573 users

How to generate a random integer between min and max in Dart

2 Answers

0 votes
import 'dart:math';

void main() {
  
    Random rnd = new Random();
  
    int min = 7, max = 15;
  
    for (int i = 0; i < 30; i++) {
        print(min + rnd.nextInt(max - min + 1));
    }
}




/*
run:

11
9
7
10
15
14
11
10
14
14
12
7
11
15
8
10
11
13
13
7
15
9
12
7
8
7
14
10
15
8

*/

 



answered Oct 19, 2022 by avibootz
0 votes
import 'dart:math';

void main() {
  
    var now = new DateTime.now();
    Random rnd = new Random(now.millisecondsSinceEpoch);
  
    int min = 7, max = 15;
  
    for (int i = 0; i < 30; i++) {
        print(min + rnd.nextInt(max - min + 1));
    }
}




/*
run:

8
15
9
14
12
7
7
7
9
13
11
7
11
7
10
7
13
9
12
15
9
12
7
9
14
9
11
10
8
7

*/

 



answered Oct 19, 2022 by avibootz

Related questions

2 answers 262 views
2 answers 188 views
188 views asked Oct 19, 2022 by avibootz
4 answers 1,730 views
1 answer 214 views
1 answer 171 views
2 answers 226 views
226 views asked Oct 19, 2022 by avibootz
...