I would like to write that code in delphi , i have tried to do it but no luck
$uid = $i=0; while($i<12){ $i++;}
$uid += floor(rand() * 10);
which it generate a random integer like this 106128013013
how it can be done in delphi ??
i took php code from here
// edit
this code generate only 8 digits and only last number changes
while i < 12 do
begin
inc(i);
end;
uid := uid + floor(random * 10);
i need this number for uploading files to xfilesharing pro script like the code in the php
i found javascript code in the script it self
var UID='';
for(var i=0;i<12;i++)UID+=''+Math.floor(Math.random() * 10);
Basic "pseudo-code" transcription is this
uid = 0
i = 0
while i < 12
begin
i = i + 1
end
uid = uid + floor(rand * 10)
Description of the PHP rand
function is here: http://www.php.net/manual/en/function.rand.php
Description of the floor
function is here: http://cz1.php.net/manual/en/function.floor.php
To me it looks like the piece of code just calls a library function that generates random number. Delphi also has a Rand
function - use your help file (I don't have it anymore).
Whatever is the reason why you want to write it in Delphi - there is no hidden gem in the referenced code worse the trouble
EDIT: pseudo-code of the JavaScript code is
UID := ''
for i := 1 to 12
begin
UID := UID + Math.floor(Math.random() * 10)
end
Explanation of Math.random
is here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
Explanation of Math.floor
is here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
Again - there is no hidden magic inside
EDIT:
So the code generates string of 12 random digits. Some tips on how to generate string of random characters in Delphi can be found here: Generate three random characters in Delphi