Sample random password/string generator which generates 32 character strings. So, generates random numbers and keep those which are between 33 and 127 as these are the ASCII values which constitute valid text.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(0));
clock_t start = clock();
long long iterations = 0;
printf("Generating String...
" ");
for (int i = 0; i < 32; i++)
{
long long holder = 0;
while(holder < 33 || holder > 126)
{
holder = rand();
iterations++;
}
putchar(holder);
}
clock_t end = clock();
printf(" "
%.2lf s , %lld iterations & %lld avg
",(double)(end - start)/CLOCKS_PER_SEC,iterations,iterations/32);
return 0;
}
Output repeats the string DEX&H1_(okd/YVf8;49=el%<j:@"T,NU
in one form or another.
Some Outputs :
Generating String...
" DEX&H1_(okd/YVf8;49=el%<j:@"T,NU "
9.11 s , 893836506 iterations & 27932390 avg
Generating String...
" xq?!#O]tDEX&H1_(okd/YVf8;49=el%< "
7.59 s , 768749018 iterations & 24023406 avg
Generating String...
" MJxq?!#O]tDEX&H1_(okd/YVf8;49=el "
7.63 s , 748742990 iterations & 23398218 avg
Compiled with cc file.c -o file
on Clang/macOS.
question from:
https://stackoverflow.com/questions/65930954/odd-repetitions-of-patterns-when-using-rand 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…