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,895 questions

51,826 answers

573 users

How to generate 8 digits int random number in C++

1 Answer

0 votes
#include <iostream>
#include <cstdlib>
#include <ctime>
 
int generate_4_digits_random_number() {
    return rand() % 90000000 + 10000000; // // numbers from 10000000 to 99999999
}
 
int main() {
    srand(time(nullptr)); 
 
    for (int i = 0; i < 10; i++) {
        std::cout << generate_4_digits_random_number() << std::endl;
    }
}



/*
run:

94667090
10332536
31926393
59427814
97580255
45752345
65366016
34930345
41869440
29318590

*/

 



answered May 14, 2024 by avibootz

Related questions

1 answer 152 views
1 answer 130 views
1 answer 116 views
1 answer 86 views
1 answer 88 views
1 answer 89 views
...