Throwing away all that good entropy that the kernel (or whatever you call it if you're consigned to Windows) worked _so hard_ to gather! *sniff*
*grin*
Seriously, though, a quicker way to generate random numbers -- rather than just throwing away all those that aren't in your desired range, and without doing two to four comparisons per iteration -- is simply to use the random number mod the range, and add the offset. You can see what I mean (in C, however) below.
The numbers are no less random, and for any verifiably normal source of random numbers, will produce a normal distribution within your desired range -- just as will your algorithm, but in much less time, using much less processor power.
Yes, I know that it's just an eight-character password, but you know what they say about thrift beginning at home. Haphazard waste of CPU, memory, and storage on the little things is why so many commercial products are topheavy resource-hogs. </rant> *grin*
I've got good news, and I've got bad news: The universe is merely a figment of my imagination. Now are you ready for the bad news?
int min = 96; int max = 123;
int range = max-min;
int i = 0; while(i < Size){
S=str_append(S,(random()%range)+min); }
*grin*
Seriously, though, a quicker way to generate random numbers -- rather than just throwing away all those that aren't in your desired range, and without doing two to four comparisons per iteration -- is simply to use the random number mod the range, and add the offset. You can see what I mean (in C, however) below.
The numbers are no less random, and for any verifiably normal source of random numbers, will produce a normal distribution within your desired range -- just as will your algorithm, but in much less time, using much less processor power.
Yes, I know that it's just an eight-character password, but you know what they say about thrift beginning at home. Haphazard waste of CPU, memory, and storage on the little things is why so many commercial products are topheavy resource-hogs. </rant> *grin*
I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?
int min = 96;
int max = 123;
int range = max-min;
int i = 0;
while(i < Size) {
S=str_append(S,(random()%range)+min);
}