Created
July 18, 2017 02:00
-
-
Save 0001vrn/3e94396c435ae88756a1298ac13df771 to your computer and use it in GitHub Desktop.
random string generator
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> | |
| 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