How to generate 5 digits random number from 00001 to 99999 in C++

1 Answer

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

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

	for (int i = 0; i < 25; i++ ) {
        int r = (rand() % (99999)) + 1;
		std::cout << std::setfill('0') << std::setw(5) << r << "\n";
	}

	return 0;
}




/*
run:

22083
37059
13990
54464
44123
06584
39514
32357
46506
77720
98991
79906
66051
83552
56820
59646
48500
04767
85051
37387
32808
00780
54254
12205
55442

*/

 



answered Dec 10, 2020 by avibootz

Related questions

1 answer 159 views
1 answer 139 views
2 answers 176 views
1 answer 149 views
149 views asked Dec 10, 2020 by avibootz
1 answer 102 views
1 answer 106 views
1 answer 104 views
...