![]() |
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:30:47 CEST
Well I just had to know the answer to one of my questions before I go do
The question was if an unsigned version of random would be safe ?
The answer it depends on how you look at it and implement the random
If the random function would use signed multiplications it would give
Here is the sanity test program ;) =D
*** 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;
vIndication := vDeath;
vIndication := round(vDeath / 1000);
// engage ;)
// if vIndication > 0 then // dirty little hack to prevent division by zero
vSignedResult := RandomSignedSanityCheck( vTestMeToDeath );
if not CompareMem( @vSignedResult, @vUnsignedResult, 4 ) then
end;
writeln('done.');
writeln( 'press enter to continue' );
begin
writeln( 'press enter to continue' );
*** End of Code ***
Bye,
|