You are not logged in.
Pages: 1
I have several files from my camera which, according to Windows, were changed at the same time including seconds.
I though I could add some random number to the file name. I used the script:
var
DateTime: TDateTime;
begin
Randomize;
DateTime := FileTimeModified(FilePath);
FileName := 'DCIM_'
+ FormatDateTime('yyyymmdd', DateTime)
+ '_'
+ FormatDateTime('hhnnss', DateTime)
+ '_'
+ IntToStr(Random(10))
+ WideExtractFileExt(FileName);
end.
I got the following error: Unknown identifier 'Random'.
Why is "Random" not supported? It is the basic math function.
Offline
Why is "Random" not supported?
There is a whole set of random generator functions:
function RandomRange(const AFrom, ATo: Integer): Integer;
function RandomFloat: Extended;
function RandomBoolean: Boolean;
The Random function was never added because a superior function RandomRange can easily do its job.
By the way, you shouldn't call Randomize more than once per renaming cycle, as stated in the documentation. If you do, its effect will be greatly diminished.
To call it only once you can use a dummy initialization variable, like so:
var
Initialized: Boolean;
begin
if not Initialized then
begin
Randomize;
Initialized := True;
end;
end.
Also, you can use a new built-in Randomize rule which is available since v6.6.0.3 Beta. It was part of the Serialize rule in prior versions.
Offline
Thanks!
Offline
Pages: 1