Created
September 29, 2016 20:27
-
-
Save abhijeetchopra/8e3068ef30702aeed84af0bb1fb87dd7 to your computer and use it in GitHub Desktop.
Randomly generate string with characters and numbers in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <stdlib.h> | |
using namespace std; | |
string randomString() | |
{ | |
string str = "AAAAAA"; | |
// string sequence | |
str[0] = rand() % 26 + 65; | |
str[1] = rand() % 26 + 65; | |
str[2] = rand() % 26 + 65; | |
// number sequence | |
str[3] = rand() % 10 + 48; | |
str[4] = rand() % 10 + 48; | |
str[5] = rand() % 10 + 48; | |
return str; | |
} | |
int main() { | |
cout << randomString(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment