Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention. Check out this how-to article for more information.

Solved

Posted on 2006-05-16

I have writtern the folowing function

function RandGen(option : integer; aWordLen : integer) : string;

var

aSRC, LettersNumbers, Letters, Numbers : string;

begin

LettersNumbers := 'abcdefghijklmnoprstuvzyxwqABCDEFGHIJKLMNOPRSTUVZXYQW1234567890';

Letters := 'abcdefghijklmnoprstuvzyxwqABCDEFGHIJKLMNOPRSTUVZXYQW';

Numbers := '1234567890';

if option = 1 then aSRC := LettersNumbers;

if option = 2 then aSRC := Letters;

if option = 3 then aSRC := Numbers;

result := '';

while Length(result) <= aWordLen do

result := result + aSRC[Random(Length(aSRC))];

end;

And i'm calling this function from loop which will repeat 20 times like this

var := varP + RandGen(2, Random(5) + 5) + RandGen(3, Random(3));

var2 := RandGen(1, Random(4) + 6);

So my program need to genrete for example 20 strings, but when it generetes 1 or 2 or 5 or... i get error. "Index was outside the bounds of the array."

Can you tell me what is the problem and fix the code.

Thank you !

function RandGen(option : integer; aWordLen : integer) : string;

var

aSRC, LettersNumbers, Letters, Numbers : string;

begin

LettersNumbers := 'abcdefghijklmnoprstuvzyxw

Letters := 'abcdefghijklmnoprstuvzyxw

Numbers := '1234567890';

if option = 1 then aSRC := LettersNumbers;

if option = 2 then aSRC := Letters;

if option = 3 then aSRC := Numbers;

result := '';

while Length(result) <= aWordLen do

result := result + aSRC[Random(Length(aSRC))]

end;

And i'm calling this function from loop which will repeat 20 times like this

var := varP + RandGen(2, Random(5) + 5) + RandGen(3, Random(3));

var2 := RandGen(1, Random(4) + 6);

So my program need to genrete for example 20 strings, but when it generetes 1 or 2 or 5 or... i get error. "Index was outside the bounds of the array."

Can you tell me what is the problem and fix the code.

Thank you !

3 Comments

result := result + aSRC[Random(Length(aSRC))+

Regards,

Russell

but however i made a another way most simple to do the same thing.

function RandGen(option : integer; aWordLen : integer) : string;

var

x : integer;

begin

result := ''; //clear result

Randomize; //start with randomized values

case option of

1 : begin //Letters and numbers

for x := 1 to awordlen do

case random(3) of

0: result := result+ char(randomrange(ord('a'),

1: result := result+uppercase(char(rand

2: result := result+ char(randomrange(ord('0'),

end;

end;

2 : begin //Letters

for x := 1 to awordlen do

case random(2) of

0: result := result+ char(randomrange(ord('a'),

1: result := result+uppercase(char(rand

end;

end;

3 : begin //numbers

for x := 1 to awordlen do

result := result+char(randomrange(or

end;

end; // end of case

end;

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Course of the Month19 days, 21 hours left to enroll

Join the community of 500,000 technology professionals and ask your questions.