Skip to content

Instantly share code, notes, and snippets.

@abhijeetchopra
Created September 29, 2016 20:27
Show Gist options
  • Save abhijeetchopra/8e3068ef30702aeed84af0bb1fb87dd7 to your computer and use it in GitHub Desktop.
Save abhijeetchopra/8e3068ef30702aeed84af0bb1fb87dd7 to your computer and use it in GitHub Desktop.
Randomly generate string with characters and numbers in C++
#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