Random Alphanumeric

#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

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!