Jump to content
Ranqers

Help Function? Maybe?

Recommended Posts

I need to make a code to generate a 4-12 character Text (username) thats different each time.

 

I'm not sure how I would devise this code. Any ideas, suggestions, tips/tricks?

 

Edit: Umh this is kinda what I wanted, I made it... But I think it could be better?

 

program New;
{.include procedures.scar}
var a,b,c,d,e,f,g,h,r: Integer;
const SN = 'Syn'; //3-Letters Start Name

procedure scramble;
begin
 a := 0+Random(525990);
 b := 0+Random(52340);
 c := 0+Random(256721);
 d := c+Random(678945);
 e := d+Random(512324);
 f := e+Random(102368);
 g := f+Random(203498);
 h := g+Random(104532);
 R := a+b+c+d+e+f+g+h;
end;

procedure write;
begin
 Wait(5);
 WriteLn(SN+IntToStr(R));       
end;  

begin
scramble;
WriteLn(IntToStr(R));
write;
end.

Edited by Ranqers
Link to comment
Share on other sites

I have just the thing. But it uses a website that does it for you. Here is the function, you would have to cut the username so it doesn't exceed 12 characters.

 

[scar]

program New;

 

function GetUsername: string;

var

Page: string;

begin

Result := '';

Page := Trim(GetPage('http://www.fakenamegenerator.com/index.php'));

if Page <> '' then

begin

Result := Trim(Copy(Page, (PosEx('<li>', Page, Pos('Username:', Page)) + 4), (PosEx('</li>', Page, (PosEx('<li>', Page, Pos('Username:', Page)) + 4))) - (PosEx('<li>', Page, Pos('Username:', Page)) + 4)));

{while Pos(' ', Result) <> 0 do // Will remove spaces from username

Delete(Charname, Pos(' ', CharName), 1);}

end;

end;

 

var

s: string;

 

begin

s := GetUsername;

WriteLn(s)

WriteLn(Copy(s, 0, 12));

end.

 

[/scar]

Link to comment
Share on other sites

Like this?

 

[scar]const

SN = 'Syn'; //3-Letters Start Name

Chars = 'abcdefghijklmnopqrstuvwqyzABCDEFGHIKJLMNOPQRSTUVWXYZ';

MinLen = 4;

MaxLen = 12;

 

function RandomChar: Char;

begin

Result := Chars[Random(Length(Chars)) + 1];

end;

 

var

Idx, Len: Integer;

Name: string;

 

begin

Len := MinLen + Random(MaxLen - MinLen + 1);

Name := SN;

for Idx := MinLen to Len do

Name := Name + RandomChar;

WriteLn(Name);

end.

[/scar]

Link to comment
Share on other sites

Hello Ranqers, are you looking for something like this:

 

const
 SN = 'Syn'; //3-Letters Start Name
 NC = 25; // How many names we generate?
 RND = 7; // Digits of random numbers after name? (minimum is 1 and maximum is 9)
          // 1 = 1-9, 2 = 10-99, 3 = 100-999, 4 = 1000-9999, etc...

function GenerateNumber(digits: Integer; var usedNumbers: TIntArray): Integer; // Returns -1 if digits is not in range of 1-9. Also returns -1 if we have reached maximum amount of possible random numbers.
var
 s, e: Integer;
begin
 Result := -1;
 if ((digits > 0) and (digits < 10)) then  
 begin    
   s := StrToInt('1' + StringOfChar('0', (digits - 1)));
   e := StrToInt('1' + StringOfChar('0', digits));
   if (Length(usedNumbers) < (e - s)) then
   begin  
     repeat
       Result := RandomRange(s, e);
     until not TIAContains(usedNumbers, Result);
     TIAAppend(usedNumbers, Result);
   end;
 end;
end;

var
 i: Integer;
 new_name: string;
 usedRN: TIntArray; // We need this for verifying the generated numbers, to keep all the results unique.  Stores the generated numbers.

begin                   
 ClearDebug;           
 for i := 1 to NC do
 begin                                               
   new_name := (SN + IntToStr(GenerateNumber(RND, usedRN))); 
   WriteLn('new_name (' + IntToStr(i) + ') = ' + new_name);
 end; 
 SetLength(usedRN, 0);
end.

 

-Jani

Edited by Janilabo
Link to comment
Share on other sites

I have just the thing. But it uses a website that does it for you. Here is the function, you would have to cut the username so it doesn't exceed 12 characters.

 

[scar]

program New;

 

function GetUsername: string;

var

Page: string;

begin

Result := '';

Page := Trim(GetPage('http://www.fakenamegenerator.com/index.php'));

if Page <> '' then

begin

Result := Trim(Copy(Page, (PosEx('<li>', Page, Pos('Username:', Page)) + 4), (PosEx('</li>', Page, (PosEx('<li>', Page, Pos('Username:', Page)) + 4))) - (PosEx('<li>', Page, Pos('Username:', Page)) + 4)));

{while Pos(' ', Result) <> 0 do // Will remove spaces from username

Delete(Charname, Pos(' ', CharName), 1);}

end;

end;

 

var

s: string;

 

begin

s := GetUsername;

WriteLn(s)

WriteLn(Copy(s, 0, 12));

end.

 

[/scar]

 

didnt work:x

Link to comment
Share on other sites

Like this?

 

[scar]const

SN = 'Syn'; //3-Letters Start Name

Chars = 'abcdefghijklmnopqrstuvwqyzABCDEFGHIKJLMNOPQRSTUVWXYZ';

MinLen = 4;

MaxLen = 12;

 

function RandomChar: Char;

begin

Result := Chars[Random(Length(Chars)) + 1];

end;

 

var

Idx, Len: Integer;

Name: string;

 

begin

Len := MinLen + Random(MaxLen - MinLen + 1);

Name := SN;

for Idx := MinLen to Len do

Name := Name + RandomChar;

WriteLn(Name);

end.

[/scar]

 

 

you are a god, did you just think that up from the top of your head?

Link to comment
Share on other sites

Well, "MinLen + Random(MaxLen - MinLen + 1);" generates a random number from, in this case 4 to 12, because Random(9) generates a number from 0 to 8. This will be the length of the added characters. Then it just loops and keeps adding random characters to the username. Though, I do spot a little bug in there.

 

This will fix it:

[scar]const

SN = 'Syn'; //3-Letters Start Name

Chars = 'abcdefghijklmnopqrstuvwqyzABCDEFGHIKJLMNOPQRSTUVWXYZ';

MinLen = 4;

MaxLen = 12;

 

function RandomChar: Char;

begin

Result := Chars[Random(Length(Chars)) + 1];

end;

 

var

Idx, Len, CurLen: Integer;

Name: string;

 

begin

Len := MinLen + Random(MaxLen - MinLen + 1);

Name := SN;

CurLen := Length(Name);

for Idx := CurLen to Len do

Name := Name + RandomChar;

WriteLn(Name);

end.[/scar]

 

So you just generate random characters to add to your already existing startstring until you reach the random length it picked which is somewhere from 4 upto 12.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...