Difference between revisions of "ReNamer:Scripts:Random characters and length"

From den4b Wiki
Jump to navigation Jump to search
m (Text replacement - "<source>" to "<syntaxhighlight lang="pascal">")
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
Line 42: Line 42:
 
   FileName[BaseLength + 1] := '.';
 
   FileName[BaseLength + 1] := '.';
 
end.
 
end.
</source>
+
</syntaxhighlight>

Latest revision as of 16:05, 8 February 2017

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.