Re: Password Generator
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 27 Oct 2005 21:22:39 +0200
"Nicholas Sherlock" <n_sherlock@xxxxxxxxxxx> wrote in message
news:djr7ao$nk4$1@xxxxxxxxxxxxxxxxxx
> Dr John Stockton wrote:
<obvious version with magic number>
> Small change:
>
> const S =
> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
>
> function Password( NumChars: integer): string;
> var CharCount: integer;
> begin
> result := '';
> for CharCount := 1 to NumChars
> do result := result + S[random(length(s))+1];
> end;
>
> This way you can add more characters to your string without having to
> count them up :).
Another small change:
function Password( NumChars: integer): string;
var CharCount: integer;
begin
SetLength(Result, NumChars);
for CharCount := 1 to NumChars
do Result[CharCount] := S[random(length(s))+1];
end;
I have a hunch that this reduces the function from potentially quadratic
to guaranteed linear time.
Groetjes,
Maarten Wiltink
.
- Follow-Ups:
- Re: Password Generator
- From: Dr John Stockton
- Re: Password Generator
- References:
- Password Generator
- From: Ryan Styles
- Re: Password Generator
- From: Charles Appel
- Re: Password Generator
- From: Dr John Stockton
- Re: Password Generator
- From: Nicholas Sherlock
- Password Generator
- Prev by Date: Table does not reflect any changes
- Next by Date: dynamic object creation
- Previous by thread: Re: Password Generator
- Next by thread: Re: Password Generator
- Index(es):