char *rand_str(char *dst, int size) { static const char text[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; entropy_clock(); int i, len = random() % (size - 1); if( !len ) len=8; for ( i=0; i<len; ++i ) dst[i] = text[random() % (sizeof text - 1)]; dst[i] = '\0'; return dst; }
// returns random line from file char *Random_linefile(char * namefile) { FILE *f; int nLines = 0; static char line[1024]; // think recv space to nullbyte 1023 int randLine=0,i=0; entropy_clock(); // i set entropy seed here memset(line,0x0,1023); f = fopen(namefile, "r"); if ( f == NULL ) { // fclose(f); DEBUG("error in file"); exit(1); } while ( !feof(f) ) { if(fgets(line, 1023, f)!=NULL) nLines++; } randLine = rand() % nLines; fseek(f, 0, SEEK_SET); while (!feof(f) && i <= randLine) if(fgets(line, 1023, f)!=NULL) i++; if( fclose(f) == EOF ) { DEBUG("error in close() file %s",namefile); exit(1); } f=NULL; return line; }