strlength

random string gen

May 4th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. //headers
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. //random strings
  7. const char letterz[] = "ABCDEFGHIJKLMNOPQRSTUVWUXYZ1234567890-_*&%$#@!><";
  8. int hack(int RSS) { return rand() % RSS; }
  9. char *RS(int length) {
  10. char *str = malloc((length + 1) * sizeof(char));
  11. int i;
  12. for (i = 0; i < length; i++) {
  13. str[i] = letterz[hack(strlen(letterz))];
  14. }
  15. str[length] = '\0';
  16. return str;
  17. }
  18. int main() {
  19. srand(time(NULL));
  20. char *random;
  21. random = RS(10);
  22. printf("%s\n", random);
  23. free(random);
  24. }
Add Comment
Please, Sign In to add comment