ReNamer:Scripts:Random characters and length

From den4b Wiki
Revision as of 03:12, 3 October 2011 by Den4b (talk | contribs) (Created page with "{{Up|ReNamer:Scripts}} Generate new names consisting of random selection of characters and of random length. Below are the parameters of the script: * CHARS - set of characters...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Generate new names consisting of random selection of characters and of random length.

Below are the parameters of the script:

  • CHARS - set of characters that are to be used for generation of new name;
  • LENGTH_MIN - minimum length of the base name;
  • LENGTH_MAX - maximum length of the base name;
  • LENGTH_EXT - length of the extension (not counting the dot).

Tested

  • ReNamer 5.60

Code

Author: Denis Kozlov. Date: 3 October 2011.

const
  CHARS = 'abcdefghijklmnopqrstuvwxyz';
  LENGTH_MIN = 5;
  LENGTH_MAX = 20;
  LENGTH_EXT = 3;
var
  I, CharIndex, BaseLength, FullLength: Integer;
  Initialized: Boolean;
begin
  if not Initialized then
  begin
    Initialized := True;  
    Randomize;
  end;
  BaseLength := RandomRange(LENGTH_MIN, LENGTH_MAX + 1);
  FullLength := BaseLength + LENGTH_EXT + 1;
  SetLength(FileName, FullLength);
  for I := 1 to FullLength do
  begin
    CharIndex := RandomRange(1, Length(CHARS) + 1);
    FileName[I] := CHARS[CharIndex];
  end;
  FileName[BaseLength + 1] := '.';
end.