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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,974 questions

51,918 answers

573 users

How to generate random number from 1 to 99999 in C++

1 Answer

0 votes
#include <iostream>
#include <ctime>
 
int main()
{
    srand((unsigned) time(0));
 
    for (int i = 0; i < 30; i++ ) {
        int r = (rand() % (99999)) + 1;
        std::cout << r << "\n";
    }
 
    return 0;
}
 
 
 
 
/*
run:
 
85094
17504
18802
8166
13652
7334
45772
66734
82649
29801
8310
44454
60640
43002
12876
15496
27619
61156
76124
778
29174
36686
16367
82204
38287
35818
91393
6789
68537
11626
 
*/

 



answered Dec 10, 2020 by avibootz

Related questions

1 answer 141 views
3 answers 315 views
1 answer 152 views
1 answer 92 views
1 answer 97 views
1 answer 86 views
1 answer 93 views
...