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

51,831 answers

573 users

How to generate 8 digit random number in C++

1 Answer

0 votes
#include <iostream>
#include <cstdlib>
#include <ctime>

#define N 20

using namespace std;

int main()
{
	srand((unsigned)time(NULL));

	long x = 1000000;
	long y = 99999999;

	for (int i = 0; i < N; i++)
		cout << rand() % (y - x + 1) + x << endl;

	return 0;
}


/*
run:

1006861
1026962
1028290
1005225
1011076
1004660
1019278
1017646
1023865
1026884
1023305
1019065
1023196
1016906
1027308
1008373
1018623
1009311
1016315
1009886

*/

 



answered Apr 26, 2016 by avibootz

Related questions

1 answer 221 views
221 views asked Apr 26, 2016 by avibootz
1 answer 157 views
1 answer 180 views
1 answer 352 views
1 answer 183 views
1 answer 678 views
...