Skip to content

Instantly share code, notes, and snippets.

@0001vrn
Created July 18, 2017 02:00
Show Gist options
  • Select an option

  • Save 0001vrn/3e94396c435ae88756a1298ac13df771 to your computer and use it in GitHub Desktop.

Select an option

Save 0001vrn/3e94396c435ae88756a1298ac13df771 to your computer and use it in GitHub Desktop.
random string generator
#include <iostream>
using namespace std;
static char *rand_string(char *str, size_t size)
{
const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJK...";
if (size) {
--size;
for (size_t n = 0; n < size; n++) {
int key = rand() % (int) (sizeof charset - 1);
str[n] = charset[key];
}
str[size] = '\0';
}
return str;
}
int main() {
// your code goes here
char s[]="varun";
rand_string(s,6);
cout<<s;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment