![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
sci.crypt archiveRe: 63/64 bit version of Delphi's function random( aRange : integer ) : integer; ?
From: Skybuck Flying <spam@hotmail.com>
Date: Fri Apr 28 2006 - 08:52:43 CEST
And finally here it is...
A working version of delphi's random function in pure delphi.
I still don't understand the overflow problem... and I am getting quite
So I simply took the lazy way and copied the problem variables to larger
So far version 0.03 is working quite nicely...
The only thing left to do now is create a 64 bit version which should be
Here is the update code:
*** Begin of Code ***
program Project1;
{
Reverse Enginering Delphi's Random function from assembler back to pure
Mostly to create a 63/64 bit version of the same random function ;)
version 0.01 created on 28 april 2006 by Skybuck Flying.
Routine version 0.03 is the fixed routine and produces the same results
}
{$APPTYPE CONSOLE}
uses
// version 0.01, problem integer overflow.
with vCombinedRegisters do
// EAX is probably initialized with the parameter of the function.
// PUSH EBX
// XOR EBX, EBX
// IMUL EDX,[EBX].RandSeed,08088405H
// INC EDX
// MOV [EBX].RandSeed,EDX
// MUL EDX
// *** problem code, integer overflow ***
// MOV EAX,EDX
// POP EBX
// version 0.02, problem still integer overflow.
with vCombinedRegisters1 do
// EAX is probably initialized with the parameter of the function.
// PUSH EBX
// XOR EBX, EBX
// IMUL EDX,[EBX].RandSeed,08088405H
// INC EDX
// MOV [EBX].RandSeed,EDX
// MUL EDX
// *** problem code, still integer overflow ***
// MOV EAX,EDX
// POP EBX
// version 0.03, fixed the problem the lazy way ;)
with vCombinedRegisters do
// EAX is probably initialized with the parameter of the function.
// PUSH EBX
// XOR EBX, EBX
// IMUL EDX,[EBX].RandSeed,08088405H
// INC EDX
// MOV [EBX].RandSeed,EDX
// MUL EDX
// *** problem code, integer overflow ***
vLargeEAX := EAX;
Large := vLargeEAX * vLargeEDX;
// MOV EAX,EDX
// POP EBX
end;
var
// CopyOfRandSeed := 0;
for I := 1 to 10 do
// call to flawed version
// call to corrected/fixed version
writeln;
writeln( 'press enter to continue' );
*** End of Code ***
Bye,
|