SRL Archive - OSR Help

Random


Death12652

2010-05-07 21:35:13

Is there a way for scar to use the random function to create random usernames or just random letters. This isn't for runescape by the way. Just a question. For example if you use the random(26) and each number 1-26 corresponds to a letter and then does that for a 10 letter word. Then types that word with a typekeys(x) function. If someone knows how to do this it would be a great help.

Dgby714

2010-05-07 22:00:07

i made this awhile back

function RandStr(Length: integer): string;
var
TSA: TStringArray;
I: integer;
begin
TSA := ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z'];

for I := 1 to Length do
Result := Result + TSA[Random(High(TSA) + 1)];
end;

Nava2

2010-05-07 23:25:17

function randStr(len: Integer): String;
var
ind, i: Integer;
chars: String;
begin
chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
for i := 1 to len do
if (random(0) = 1) then
result := result + uppercase(chars[random(len) + 1]);
else
result := result + chars[random(len) + 1];
end;

Dgby714

2010-05-08 00:02:33

From: Nava2
function randStr(len: Integer): String;
var
ind, i: Integer;
chars: String;
begin
chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
for i := 1 to len do
if (random(0) = 1) then
result := result + uppercase(chars[random(len) + 1]);
else
result := result + chars[random(len) + 1];
end;


I think you broke yours =/ if len > Length(char) then it will error should be

function RandStr(Len: Integer): string;
var
I: Integer;
Chars: string;
begin
Chars := 'abcdefghijklmnopqrstuvwxyz0123456789';
for i := 1 to Len do
if (Random(2) = 1) then
Result := Result + uppercase(Chars[Random(Length(Chars)) + 1])
else
Result := Result + Chars[Random(Length(Chars)) + 1];
end;

Nava2

2010-05-08 00:19:00

This should work:

function RandStr(Len: Integer): string;
var
I, cLen: Integer;
Chars: string;
begin
Chars := 'abcdefghijklmnopqrstuvwxyz0123456789';
cLen := length(chars);
for i := 1 to Len do
if (Random(2) = 1) then
Result := Result + uppercase(Chars[Random(cLen) + 1])
else
Result := Result + Chars[Random(cLen) + 1];
end;

Dgby714

2010-05-08 00:44:40

From: Nava2
This should work:

function RandStr(Len: Integer): string;
var
I, cLen: Integer;
Chars: string;
begin
Chars := 'abcdefghijklmnopqrstuvwxyz0123456789';
cLen := length(chars);
for i := 1 to Len do
if (Random(2) = 1) then
Result := Result + uppercase(Chars[Random(cLen) + 1])
else
Result := Result + Chars[Random(cLen) + 1];
end;


Yeah i posted yours again edited to work =)

Death12652

2010-05-08 04:15:26

Thanks Guys, I will make sure to give said person credit for whichever one I decide to use. The script will only be used by me and like two other friends and wont be on SRL so thanks.

Disregard what it used to say here I got it to work… I'm using Nava2's function after he fixed it.

Thanks,

Death