Fri Nov 08 2019

Random Alphanumeric

C++ Programming2308 views

File Name: random-alphanumeric.cpp

#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
Reference:

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