![]() |
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 - 12:50:28 CEST
This is also an interesting deviation of the test program.
The maximum value is always inputted into the random function and the max
The rest is the same but what the fuck here is the complete code one more
*** Begin of Code ***
program RandomSanityCheck;
{
Reverse Enginering Delphi's Random function from assembler back to pure
Mostly to create a 63/64 bit version of the same random function ;)
Mission impossible sir !
Need to known the algorithm to make a 64 bit version ;)
Check out Lehmer's pseudo random number generator alghorithm for thez
}
{
version 0.02 created on 28 april 2006 by Skybuck Flying.
This signed vs unsigned shit is driving me crazy.
Time to cut off some crap code and time to test it to death...
ME MUST KNOW THE ANSWER BEFORE I STOP ;)
CANT GET IT OF MY MIND lol.
MUST GO ON hehehehe.
The VENDETTA music is playing now... messing with my concentration..
but this is not so a difficult task no sir bob...
It's just the last straw =D Wieeeeeeeeeeeeeeee.
Can do that with music on ;) Yes sir bob ! =D
Only doubt is int64 multiplication which will always be signed ?!
Delphi lacks unsigned int64 !?
}
{$APPTYPE CONSOLE}
uses
// version 0.04 based on version 0.03
function RandomSignedSanityCheck( ParaRange : integer ) : integer;
EAX : longword;
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;
// version 0.04 based on version 0.03
function RandomUnsignedSanityCheck( ParaRange : longword ) : longword;
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;
procedure Main;
vSignedResult : integer;
vMaxResult : longword;
vIndication := round(vDeath / 1000);
vMaxResult := 0;
// engage ;)
// vSignedResult := RandomSignedSanityCheck( vTestMeToDeath );
vSignedResult := RandomSignedSanityCheck( vDeath );
if not CompareMem( @vSignedResult, @vUnsignedResult, 4 ) then
end;
writeln('done.');
writeln( 'press enter to continue' );
begin
writeln( 'press enter to continue' );
*** End of Code ***
The absolute maximum result was indeed generated.
Bye,
|