Random Alphanumeric

C++ Programming

C++ Programming Examples

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;

int main() {

	/* Decleration and initialization of static constant string type variable */
	static const string charList = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	/* srand() initialize random number generator */
	/* time() for get current time */
	srand(time(0));
	string alphanumeric = "";
	
	for(int i = 0; i < 8; i++) {
		/* rand() generate random number */
		alphanumeric += charList [rand() % charList.size()];
	}
	
	cout << "Random Alphanumeric: " << alphanumeric << endl;
	return 0;
}


          /****** Output ******/
          

Random Alphanumeric: m7csZCs7

Learn more about Random Alphanumeric of Password