Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* geraStringAleatoria(){
- char *validchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- char *novastr;
- register int i;
- int str_len;
- // novo tamanho
- str_len = (rand() % MAX_STR_SIZE );
- // checa tamanho
- str_len += ( str_len < MIN_STR_SIZE ) ? MIN_STR_SIZE : 0;
- // aloca memoria
- novastr = ( char * ) malloc ( (str_len + 1) * sizeof(char));
- if ( !novastr ){
- printf("[*] Erro ao alocar memoria.n" );
- exit ( EXIT_FAILURE );
- }
- // gera string aleatória
- for ( i = 0; i < str_len; i++ ) {
- novastr[i] = validchars[ rand() % strlen(validchars) ];
- novastr[i + 1] = 0x0;
- }
- return novastr;
- }
Add Comment
Please, Sign In to add comment