No hay necesidad de preguntarle a MS.
El codigo desensamblado es mas o menos asi:
Código Delphi
[-]
function Random.InternalSample: Integer;
begin
index := self.inext;
inextp := self.inextp;
if (++index >= $38) then
index := 1;
if (++inextp >= $38) then
inextp := 1;
num := (self.SeedArray[index] - self.SeedArray[inextp]);
if (num < 0) then
inc(num, $7fffffff);
self.SeedArray[index] := num;
self.inext := index;
self.inextp := inextp;
begin
Result := num;
exit
end
end;
function Random.Next(minValue: Integer; maxValue: Integer): Integer;
begin
if (minValue > maxValue) then
raise ArgumentOutOfRangeException.Create('minValue', string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString('Argument_MinMaxValue'), New(array[2] of TObject, ( ( 'minValue', 'maxValue' ) ))));
num := (maxValue - minValue);
if (num <= $7fffffff) then
begin
Result := (((self.Sample * num) as Integer) + minValue);
exit
end;
begin
Result := ((((self.GetSampleForLargeRange * num) as Int64) as Integer) + minValue);
exit
end
end;
function Random.Next: Integer;
begin
Result := self.InternalSample
end;
function Random.Sample: Double;
begin
Result := (self.InternalSample * 4.6566128752457969E-10)
end;
function Random.GetSampleForLargeRange: Double;
begin
num := self.InternalSample;
if ( (if ((self.InternalSample mod 2) = 0) then 1 else 0) <> 0) then
num := -num;
num2 := num;
inc(num2, 2147483646);
begin
Result := (num2 div 4294967293);
exit
end
end
NOTA: Es solo una porcion y el desemsamblaje no es perfecto.
Ahora, para una mejor aproximacion quizas el codigo de MONO nos sirva:
Código:
public class Random
{
const int MBIG = int.MaxValue;
const int MSEED = 161803398;
const int MZ = 0;
int inext, inextp;
int [] SeedArray = new int [56];
public Random ()
: this (Environment.TickCount)
{
}
public Random (int Seed)
{
int ii;
int mj, mk;
// Numerical Recipes in C online @ http://www.library.cornell.edu/nr/bookcpdf/c7-1.pdf
mj = MSEED - Math.Abs (Seed);
SeedArray [55] = mj;
mk = 1;
for (int i = 1; i < 55; i++) { // [1, 55] is special (Knuth)
ii = (21 * i) % 55;
SeedArray [ii] = mk;
mk = mj - mk;
if (mk < 0)
mk += MBIG;
mj = SeedArray [ii];
}
for (int k = 1; k < 5; k++) {
for (int i = 1; i < 56; i++) {
SeedArray [i] -= SeedArray [1 + (i + 30) % 55];
if (SeedArray [i] < 0)
SeedArray [i] += MBIG;
}
}
inext = 0;
inextp = 31;
}
protected virtual double Sample ()
{
int retVal;
if (++inext >= 56) inext = 1;
if (++inextp >= 56) inextp = 1;
retVal = SeedArray [inext] - SeedArray [inextp];
if (retVal < 0)
retVal += MBIG;
SeedArray [inext] = retVal;
return retVal * (1.0 / MBIG);
}
public virtual int Next ()
{
return (int)(Sample () * int.MaxValue);
}
public virtual int Next (int maxValue)
{
if (maxValue < 0)
throw new ArgumentOutOfRangeException(Locale.GetText (
"Max value is less then min value."));
return (int)(Sample () * maxValue);
}
public virtual int Next (int minValue, int maxValue)
{
if (minValue > maxValue)
throw new ArgumentOutOfRangeException (Locale.GetText (
"Min value is greater then max value."));
uint diff = (uint)(maxValue - minValue);
if (diff == 0)
return minValue;
int result = (int)(Sample () * diff + minValue);
return ((result != maxValue) ? result : (result - 1));
}
public virtual void NextBytes (byte [] buffer)
{
if (buffer == null)
throw new ArgumentNullException ("buffer");
for (int i = 0; i < buffer.Length; i++) {
buffer [i] = (byte)(Sample () * (byte.MaxValue + 1));
}
}
public virtual double NextDouble ()
{
return this.Sample ();
}
}
Otra solucion seria crear una DLL en Delphi que haga el codigo de random e invocar desde VB.NET con PInvoke, asi se garantizaria una unica implementacion.