چگونگی کار با کلاس رندوم(Random) یک کلاس به زبانهای(C#,C++,VB,IL,Chorme,Delphi) تحت دات نت
سلام خدمت همه دوستان برنامه نویس پی سی.
دلیل اینکه یه تاپیک جدا هم زدم فقط چون موضوع خاصی بود (با عرض پوزش).
حقیقاً من طی چند سالی که با چند نفر از دوستان و آشنایان با برنامه نویسی کار میکردم اکثراً سوالاتشون این بود که مایکروسافت چگونه عدد رندوم رو با کلاس Random بر میگردونه!!
منم رفتم دنبالش که بالاخره پیدا کردم کلاسش رو به زبان های (C#,C++,VB,IL,Chorme,Delphi) در این تاپیک قرار میدم امیدوارم که مورد استفاده قرار بگیره. فقط دوتا سوال داشتم اگه جواب بدین ممنون میشم:10:.
من تا حالا اسم IL و Chorme رو نشنیدم ممنون میشم یکی توضیح بده که اینا چه زبان هایی هستن و اگه برنامه ای دارین لطفاً معرفی کننین مرسی:11:.
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
سی شارپ(#C) کلاس:
کد:
internal class ClassRandom
{
// Fields
private int inext;
private int inextp;
private const int MBIG = 0x7fffffff;
private const int MSEED = 0x9a4ec86;
private const int MZ = 0;
private int[] SeedArray;
// Methods
public ClassRandom() : this(Environment.TickCount)
{
}
public ClassRandom(int Seed)
{
this.SeedArray = new int[0x38];
int num2 = 0x9a4ec86 - Math.Abs(Seed);
this.SeedArray[0x37] = num2;
int num3 = 1;
for (int i = 1; i < 0x37; i++)
{
int index = (0x15 * i) % 0x37;
this.SeedArray[index] = num3;
num3 = num2 - num3;
if (num3 < 0)
{
num3 += 0x7fffffff;
}
num2 = this.SeedArray[index];
}
for (int j = 1; j < 5; j++)
{
for (int k = 1; k < 0x38; k++)
{
this.SeedArray[k] -= this.SeedArray[1 + ((k + 30) % 0x37)];
if (this.SeedArray[k] < 0)
{
this.SeedArray[k] += 0x7fffffff;
}
}
}
this.inext = 0;
this.inextp = 0x15;
Seed = 1;
}
private double GetSampleForLargeRange()
{
int num = this.InternalSample();
if ((((this.InternalSample() % 2) == 0) ? 1 : 0) != 0)
{
num = -num;
}
double num2 = num;
num2 += 2147483646.0;
return (num2 / 4294967293);
}
private int InternalSample()
{
int inext = this.inext;
int inextp = this.inextp;
if (++inext >= 0x38)
{
inext = 1;
}
if (++inextp >= 0x38)
{
inextp = 1;
}
int num = this.SeedArray[inext] - this.SeedArray[inextp];
if (num < 0)
{
num += 0x7fffffff;
}
this.SeedArray[inext] = num;
this.inext = inext;
this.inextp = inextp;
return num;
}
public virtual int Next()
{
return this.InternalSample();
}
public virtual int Next(int maxValue)
{
if (maxValue < 0)
{
}
return (int) (this.Sample() * maxValue);
}
public virtual int Next(int minValue, int maxValue)
{
if (minValue > maxValue)
{
}
long num = maxValue - minValue;
if (num <= 0x7fffffffL)
{
return (((int) (this.Sample() * num)) + minValue);
}
return (((int) ((long) (this.GetSampleForLargeRange() * num))) + minValue);
}
public virtual void NextBytes(byte[] buffer)
{
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
for (int i = 0; i < buffer.Length; i++)
{
buffer[i] = (byte) (this.InternalSample() % 0x100);
}
}
public virtual double NextDouble()
{
return this.Sample();
}
protected virtual double Sample()
{
return (this.InternalSample() * 4.6566128752457969E-10);
}
}
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
ویژوال بیسیک(Visual Basic) کلاس:
کد:
Friend Class ClassRandom
' Methods
Public Sub New()
Me.New(Environment.TickCount)
End Sub
Public Sub New(ByVal Seed As Integer)
Me.SeedArray = New Integer(&H38 - 1) {}
Dim num2 As Integer = (&H9A4EC86 - Math.Abs(Seed))
Me.SeedArray(&H37) = num2
Dim num3 As Integer = 1
Dim i As Integer
For i = 1 To &H37 - 1
Dim index As Integer = ((&H15 * i) Mod &H37)
Me.SeedArray(index) = num3
num3 = (num2 - num3)
If (num3 < 0) Then
num3 = (num3 + &H7FFFFFFF)
End If
num2 = Me.SeedArray(index)
Next i
Dim j As Integer
For j = 1 To 5 - 1
Dim k As Integer
For k = 1 To &H38 - 1
Me.SeedArray(k) = (Me.SeedArray(k) - Me.SeedArray((1 + ((k + 30) Mod &H37))))
If (Me.SeedArray(k) < 0) Then
Me.SeedArray(k) = (Me.SeedArray(k) + &H7FFFFFFF)
End If
Next k
Next j
Me.inext = 0
Me.inextp = &H15
Seed = 1
End Sub
Private Function GetSampleForLargeRange() As Double
Dim num As Integer = Me.InternalSample
If (IIf(((Me.InternalSample Mod 2) = 0), 1, 0) <> 0) Then
num = -num
End If
Dim num2 As Double = num
num2 = (num2 + 2147483646)
Return (num2 / 4294967293)
End Function
Private Function InternalSample() As Integer
Dim inext As Integer = Me.inext
Dim inextp As Integer = Me.inextp
If (++inext >= &H38) Then
inext = 1
End If
If (++inextp >= &H38) Then
inextp = 1
End If
Dim num As Integer = (Me.SeedArray(inext) - Me.SeedArray(inextp))
If (num < 0) Then
num = (num + &H7FFFFFFF)
End If
Me.SeedArray(inext) = num
Me.inext = inext
Me.inextp = inextp
Return num
End Function
Public Overridable Function [Next]() As Integer
Return Me.InternalSample
End Function
Public Overridable Function [Next](ByVal maxValue As Integer) As Integer
If (maxValue < 0) Then
End If
Return CInt((Me.Sample * maxValue))
End Function
Public Overridable Function [Next](ByVal minValue As Integer, ByVal maxValue As Integer) As Integer
If (minValue > maxValue) Then
End If
Dim num As Long = (maxValue - minValue)
If (num <= &H7FFFFFFF) Then
Return (CInt((Me.Sample * num)) + minValue)
End If
Return (CInt(CLng((Me.GetSampleForLargeRange * num))) + minValue)
End Function
Public Overridable Sub NextBytes(ByVal buffer As Byte())
If (buffer Is Nothing) Then
Throw New ArgumentNullException("buffer")
End If
Dim i As Integer
For i = 0 To buffer.Length - 1
buffer(i) = CByte((Me.InternalSample Mod &H100))
Next i
End Sub
Public Overridable Function NextDouble() As Double
Return Me.Sample
End Function
Protected Overridable Function Sample() As Double
Return (Me.InternalSample * 4.6566128752457969E-10)
End Function
' Fields
Private inext As Integer
Private inextp As Integer
Private Const MBIG As Integer = &H7FFFFFFF
Private Const MSEED As Integer = &H9A4EC86
Private Const MZ As Integer = 0
Private SeedArray As Integer()
End Class
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
سی پلاس پلاس(++C) کلاس:
کد:
private __gc class ClassRandom
{
// Methods
public: ClassRandom() : this(Environment::TickCount)
{
}
public: ClassRandom(Int32 __gc* Seed)
{
this->SeedArray = __gc new Int32 __gc*[0x38];
Int32 __gc* num2 = (0x9a4ec86 - Math::Abs(Seed));
this->SeedArray[0x37] = num2;
Int32 __gc* num3 = 1;
for (Int32 __gc* i = 1; (i < 0x37); i++)
{
Int32 __gc* index = ((0x15 * i) % 0x37);
this->SeedArray[index] = num3;
num3 = (num2 - num3);
if (num3 < 0)
{
num3 += 0x7fffffff;
}
num2 = this->SeedArray[index];
}
for (Int32 __gc* j = 1; (j < 5); j++)
{
for (Int32 __gc* k = 1; (k < 0x38); k++)
{
this->SeedArray[k] -= this->SeedArray[(1 + ((k + 30) % 0x37))];
if (this->SeedArray[k] < 0)
{
this->SeedArray[k] += 0x7fffffff;
}
}
}
this->inext = 0;
this->inextp = 0x15;
Seed = 1;
}
private: Double __gc* GetSampleForLargeRange()
{
Int32 __gc* num = this->InternalSample();
if ((((this->InternalSample() % 2) == 0) ? 1 : 0) != 0)
{
num = -num;
}
Double __gc* num2 = num;
num2 += 2147483646;
return (num2 / 4294967293);
}
private: Int32 __gc* InternalSample()
{
Int32 __gc* inext = this->inext;
Int32 __gc* inextp = this->inextp;
if (++inext >= 0x38)
{
inext = 1;
}
if (++inextp >= 0x38)
{
inextp = 1;
}
Int32 __gc* num = (this->SeedArray[inext] - this->SeedArray[inextp]);
if (num < 0)
{
num += 0x7fffffff;
}
this->SeedArray[inext] = num;
this->inext = inext;
this->inextp = inextp;
return num;
}
public: virtual Int32 __gc* Next()
{
return this->InternalSample();
}
public: virtual Int32 __gc* Next(Int32 __gc* maxValue)
{
if (maxValue < 0)
{
}
return *static_cast<__box Int32*>((this->Sample() * maxValue));
}
public: virtual Int32 __gc* Next(Int32 __gc* minValue, Int32 __gc* maxValue)
{
if (minValue > maxValue)
{
}
Int64 __gc* num = (maxValue - minValue);
if (num <= 0x7fffffff)
{
return (*static_cast<__box Int32*>((this->Sample() * num)) + minValue);
}
return (*static_cast<__box Int32*>(*static_cast<__box Int64*>((this->GetSampleForLargeRange() * num))) + minValue);
}
public: virtual void __gc* NextBytes(Byte __gc* buffer __gc [])
{
if (buffer == 0)
{
throw __gc new ArgumentNullException(S"buffer");
}
for (Int32 __gc* i = 0; (i < buffer->Length); i++)
{
buffer[i] = *static_cast<__box Byte*>((this->InternalSample() % 0x100));
}
}
public: virtual Double __gc* NextDouble()
{
return this->Sample();
}
protected: virtual Double __gc* Sample()
{
return (this->InternalSample() * 4.6566128752457969E-10);
}
// Fields
private: Int32 __gc* inext;
private: Int32 __gc* inextp;
private: const Int32 __gc* MBIG = 0x7fffffff;
private: const Int32 __gc* MSEED = 0x9a4ec86;
private: const Int32 __gc* MZ = 0;
private: Int32 __gc* SeedArray __gc [];
};
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
دلفی(Delphi) کلاس:
کد:
strict private ClassRandom = class
// Methods
constructor ClassRandom.Create;
begin
end;
constructor ClassRandom.Create(Seed: Integer);
begin
self.SeedArray := New(array[$38] of Integer);
num2 := ($9a4ec86 - Math.Abs(Seed));
self.SeedArray[$37] := num2;
num3 := 1;
i := 1;
while ((i < $37)) do
begin
index := (($15 * i) mod $37);
self.SeedArray[index] := num3;
num3 := (num2 - num3);
if (num3 < 0) then
inc(num3, $7fffffff);
num2 := self.SeedArray[index];
inc(i)
end;
j := 1;
while ((j < 5)) do
begin
k := 1;
while ((k < $38)) do
begin
dec(self.SeedArray[k], self.SeedArray[(1 + ((k + 30) mod $37))]);
if (self.SeedArray[k] < 0) then
inc(self.SeedArray[k], $7fffffff);
inc(k)
end;
inc(j)
end;
self.inext := 0;
self.inextp := $15;
Seed := 1
end;
function ClassRandom.GetSampleForLargeRange: Double;
begin
num := self.InternalSample;
if ( {pseudo} (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;
function ClassRandom.InternalSample: Integer;
begin
inext := self.inext;
inextp := self.inextp;
if (++inext >= $38) then
inext := 1;
if (++inextp >= $38) then
inextp := 1;
num := (self.SeedArray[inext] - self.SeedArray[inextp]);
if (num < 0) then
inc(num, $7fffffff);
self.SeedArray[inext] := num;
self.inext := inext;
self.inextp := inextp;
begin
Result := num;
exit
end
end;
function ClassRandom.Next: Integer;
begin
Result := self.InternalSample
end;
function ClassRandom.Next(maxValue: Integer): Integer;
begin
if (maxValue < 0) then
;
begin
Result := ((self.Sample * maxValue) as Integer);
exit
end
end;
function ClassRandom.Next(minValue: Integer; maxValue: Integer): Integer;
begin
if (minValue > maxValue) then
;
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;
procedure ClassRandom.NextBytes(buffer: Byte[]);
begin
if (buffer = nil) then
raise ArgumentNullException.Create('buffer');
i := 0;
while ((i < buffer.Length)) do
begin
buffer[i] := ((self.InternalSample mod $100) as Byte);
inc(i)
end
end;
function ClassRandom.NextDouble: Double;
begin
Result := self.Sample
end;
function ClassRandom.Sample: Double;
begin
Result := (self.InternalSample * 4.6566128752457969E-10)
end;
// Fields
strict private inext: Integer;
strict private inextp: Integer;
strict private const MBIG: Integer = $7fffffff;
strict private const MSEED: Integer = $9a4ec86;
strict private const MZ: Integer = 0;
strict private SeedArray: Integer[];
end;
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
آی ال (information literacy Or IL) کلاس:
کد:
.class private auto ansi beforefieldinit ClassRandom
extends [mscorlib]System.Object
{
.method public hidebysig specialname rtspecialname instance void .ctor() cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: call int32 [mscorlib]System.Environment::get_TickCount()
L_0006: call instance void WindowsFormsApplication1.ClassRandom::.ctor(int32)
L_000b: nop
L_000c: nop
L_000d: nop
L_000e: ret
}
.method public hidebysig specialname rtspecialname instance void .ctor(int32 Seed) cil managed
{
.maxstack 6
.locals init (
[0] int32 num2,
[1] int32 num3,
[2] int32 i,
[3] int32 index,
[4] int32 j,
[5] int32 k,
[6] bool CS$4$0000)
L_0000: ldarg.0
L_0001: call instance void [mscorlib]System.Object::.ctor()
L_0006: nop
L_0007: nop
L_0008: ldarg.0
L_0009: ldc.i4.s 0x38
L_000b: newarr int32
L_0010: stfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_0015: ldc.i4 0x9a4ec86
L_001a: ldarg.1
L_001b: call int32 [mscorlib]System.Math::Abs(int32)
L_0020: sub
L_0021: stloc.0
L_0022: ldarg.0
L_0023: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_0028: ldc.i4.s 0x37
L_002a: ldloc.0
L_002b: stelem.i4
L_002c: ldc.i4.1
L_002d: stloc.1
L_002e: ldc.i4.1
L_002f: stloc.2
L_0030: br.s L_006d
L_0032: nop
L_0033: ldc.i4.s 0x15
L_0035: ldloc.2
L_0036: mul
L_0037: ldc.i4.s 0x37
L_0039: rem
L_003a: stloc.3
L_003b: ldarg.0
L_003c: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_0041: ldloc.3
L_0042: ldloc.1
L_0043: stelem.i4
L_0044: ldloc.0
L_0045: ldloc.1
L_0046: sub
L_0047: stloc.1
L_0048: ldloc.1
L_0049: ldc.i4.0
L_004a: clt
L_004c: ldc.i4.0
L_004d: ceq
L_004f: stloc.s CS$4$0000
L_0051: ldloc.s CS$4$0000
L_0053: brtrue.s L_005f
L_0055: nop
L_0056: ldloc.1
L_0057: ldc.i4 0x7fffffff
L_005c: add
L_005d: stloc.1
L_005e: nop
L_005f: ldarg.0
L_0060: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_0065: ldloc.3
L_0066: ldelem.i4
L_0067: stloc.0
L_0068: nop
L_0069: ldloc.2
L_006a: ldc.i4.1
L_006b: add
L_006c: stloc.2
L_006d: ldloc.2
L_006e: ldc.i4.s 0x37
L_0070: clt
L_0072: stloc.s CS$4$0000
L_0074: ldloc.s CS$4$0000
L_0076: brtrue.s L_0032
L_0078: ldc.i4.1
L_0079: stloc.s j
L_007b: br L_0100
L_0080: nop
L_0081: ldc.i4.1
L_0082: stloc.s k
L_0084: br.s L_00ed
L_0086: nop
L_0087: ldarg.0
L_0088: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_008d: ldloc.s k
L_008f: ldelema int32
L_0094: dup
L_0095: ldobj int32
L_009a: ldarg.0
L_009b: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_00a0: ldc.i4.1
L_00a1: ldloc.s k
L_00a3: ldc.i4.s 30
L_00a5: add
L_00a6: ldc.i4.s 0x37
L_00a8: rem
L_00a9: add
L_00aa: ldelem.i4
L_00ab: sub
L_00ac: stobj int32
L_00b1: ldarg.0
L_00b2: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_00b7: ldloc.s k
L_00b9: ldelem.i4
L_00ba: ldc.i4.0
L_00bb: clt
L_00bd: ldc.i4.0
L_00be: ceq
L_00c0: stloc.s CS$4$0000
L_00c2: ldloc.s CS$4$0000
L_00c4: brtrue.s L_00e6
L_00c6: nop
L_00c7: ldarg.0
L_00c8: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_00cd: ldloc.s k
L_00cf: ldelema int32
L_00d4: dup
L_00d5: ldobj int32
L_00da: ldc.i4 0x7fffffff
L_00df: add
L_00e0: stobj int32
L_00e5: nop
L_00e6: nop
L_00e7: ldloc.s k
L_00e9: ldc.i4.1
L_00ea: add
L_00eb: stloc.s k
L_00ed: ldloc.s k
L_00ef: ldc.i4.s 0x38
L_00f1: clt
L_00f3: stloc.s CS$4$0000
L_00f5: ldloc.s CS$4$0000
L_00f7: brtrue.s L_0086
L_00f9: nop
L_00fa: ldloc.s j
L_00fc: ldc.i4.1
L_00fd: add
L_00fe: stloc.s j
L_0100: ldloc.s j
L_0102: ldc.i4.5
L_0103: clt
L_0105: stloc.s CS$4$0000
L_0107: ldloc.s CS$4$0000
L_0109: brtrue L_0080
L_010e: ldarg.0
L_010f: ldc.i4.0
L_0110: stfld int32 WindowsFormsApplication1.ClassRandom::inext
L_0115: ldarg.0
L_0116: ldc.i4.s 0x15
L_0118: stfld int32 WindowsFormsApplication1.ClassRandom::inextp
L_011d: ldc.i4.1
L_011e: starg.s Seed
L_0120: nop
L_0121: ret
}
.method private hidebysig instance float64 GetSampleForLargeRange() cil managed
{
.maxstack 2
.locals init (
[0] int32 num,
[1] float64 num2,
[2] float64 CS$1$0000,
[3] bool CS$4$0001)
L_0000: nop
L_0001: ldarg.0
L_0002: call instance int32 WindowsFormsApplication1.ClassRandom::InternalSample()
L_0007: stloc.0
L_0008: ldarg.0
L_0009: call instance int32 WindowsFormsApplication1.ClassRandom::InternalSample()
L_000e: ldc.i4.2
L_000f: rem
L_0010: brfalse.s L_0015
L_0012: ldc.i4.0
L_0013: br.s L_0016
L_0015: ldc.i4.1
L_0016: ldc.i4.0
L_0017: ceq
L_0019: stloc.3
L_001a: ldloc.3
L_001b: brtrue.s L_0022
L_001d: nop
L_001e: ldloc.0
L_001f: neg
L_0020: stloc.0
L_0021: nop
L_0022: ldloc.0
L_0023: conv.r8
L_0024: stloc.1
L_0025: ldloc.1
L_0026: ldc.r8 2147483646
L_002f: add
L_0030: stloc.1
L_0031: ldloc.1
L_0032: ldc.r8 4294967293
L_003b: div
L_003c: stloc.2
L_003d: br.s L_003f
L_003f: ldloc.2
L_0040: ret
}
.method private hidebysig instance int32 InternalSample() cil managed
{
.maxstack 3
.locals init (
[0] int32 inext,
[1] int32 inextp,
[2] int32 num,
[3] int32 CS$1$0000,
[4] bool CS$4$0001)
L_0000: nop
L_0001: ldarg.0
L_0002: ldfld int32 WindowsFormsApplication1.ClassRandom::inext
L_0007: stloc.0
L_0008: ldarg.0
L_0009: ldfld int32 WindowsFormsApplication1.ClassRandom::inextp
L_000e: stloc.1
L_000f: ldloc.0
L_0010: ldc.i4.1
L_0011: add
L_0012: dup
L_0013: stloc.0
L_0014: ldc.i4.s 0x38
L_0016: clt
L_0018: stloc.s CS$4$0001
L_001a: ldloc.s CS$4$0001
L_001c: brtrue.s L_0022
L_001e: nop
L_001f: ldc.i4.1
L_0020: stloc.0
L_0021: nop
L_0022: ldloc.1
L_0023: ldc.i4.1
L_0024: add
L_0025: dup
L_0026: stloc.1
L_0027: ldc.i4.s 0x38
L_0029: clt
L_002b: stloc.s CS$4$0001
L_002d: ldloc.s CS$4$0001
L_002f: brtrue.s L_0035
L_0031: nop
L_0032: ldc.i4.1
L_0033: stloc.1
L_0034: nop
L_0035: ldarg.0
L_0036: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_003b: ldloc.0
L_003c: ldelem.i4
L_003d: ldarg.0
L_003e: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_0043: ldloc.1
L_0044: ldelem.i4
L_0045: sub
L_0046: stloc.2
L_0047: ldloc.2
L_0048: ldc.i4.0
L_0049: clt
L_004b: ldc.i4.0
L_004c: ceq
L_004e: stloc.s CS$4$0001
L_0050: ldloc.s CS$4$0001
L_0052: brtrue.s L_005e
L_0054: nop
L_0055: ldloc.2
L_0056: ldc.i4 0x7fffffff
L_005b: add
L_005c: stloc.2
L_005d: nop
L_005e: ldarg.0
L_005f: ldfld int32[] WindowsFormsApplication1.ClassRandom::SeedArray
L_0064: ldloc.0
L_0065: ldloc.2
L_0066: stelem.i4
L_0067: ldarg.0
L_0068: ldloc.0
L_0069: stfld int32 WindowsFormsApplication1.ClassRandom::inext
L_006e: ldarg.0
L_006f: ldloc.1
L_0070: stfld int32 WindowsFormsApplication1.ClassRandom::inextp
L_0075: ldloc.2
L_0076: stloc.3
L_0077: br.s L_0079
L_0079: ldloc.3
L_007a: ret
}
.method public hidebysig newslot virtual instance int32 Next() cil managed
{
.maxstack 1
.locals init (
[0] int32 CS$1$0000)
L_0000: nop
L_0001: ldarg.0
L_0002: call instance int32 WindowsFormsApplication1.ClassRandom::InternalSample()
L_0007: stloc.0
L_0008: br.s L_000a
L_000a: ldloc.0
L_000b: ret
}
.method public hidebysig newslot virtual instance int32 Next(int32 maxValue) cil managed
{
.maxstack 2
.locals init (
[0] int32 CS$1$0000,
[1] bool CS$4$0001)
L_0000: nop
L_0001: ldarg.1
L_0002: ldc.i4.0
L_0003: clt
L_0005: ldc.i4.0
L_0006: ceq
L_0008: stloc.1
L_0009: ldloc.1
L_000a: brtrue.s L_000e
L_000c: nop
L_000d: nop
L_000e: ldarg.0
L_000f: callvirt instance float64 WindowsFormsApplication1.ClassRandom::Sample()
L_0014: ldarg.1
L_0015: conv.r8
L_0016: mul
L_0017: conv.i4
L_0018: stloc.0
L_0019: br.s L_001b
L_001b: ldloc.0
L_001c: ret
}
.method public hidebysig newslot virtual instance int32 Next(int32 minValue, int32 maxValue) cil managed
{
.maxstack 2
.locals init (
[0] int64 num,
[1] int32 CS$1$0000,
[2] bool CS$4$0001)
L_0000: nop
L_0001: ldarg.1
L_0002: ldarg.2
L_0003: cgt
L_0005: ldc.i4.0
L_0006: ceq
L_0008: stloc.2
L_0009: ldloc.2
L_000a: brtrue.s L_000e
L_000c: nop
L_000d: nop
L_000e: ldarg.2
L_000f: ldarg.1
L_0010: sub
L_0011: conv.i8
L_0012: stloc.0
L_0013: ldloc.0
L_0014: ldc.i4 0x7fffffff
L_0019: conv.i8
L_001a: cgt
L_001c: stloc.2
L_001d: ldloc.2
L_001e: brtrue.s L_0030
L_0020: nop
L_0021: ldarg.0
L_0022: callvirt instance float64 WindowsFormsApplication1.ClassRandom::Sample()
L_0027: ldloc.0
L_0028: conv.r8
L_0029: mul
L_002a: conv.i4
L_002b: ldarg.1
L_002c: add
L_002d: stloc.1
L_002e: br.s L_0040
L_0030: ldarg.0
L_0031: call instance float64 WindowsFormsApplication1.ClassRandom::GetSampleForLargeRange()
L_0036: ldloc.0
L_0037: conv.r8
L_0038: mul
L_0039: conv.i8
L_003a: conv.i4
L_003b: ldarg.1
L_003c: add
L_003d: stloc.1
L_003e: br.s L_0040
L_0040: ldloc.1
L_0041: ret
}
.method public hidebysig newslot virtual instance void NextBytes(uint8[] buffer) cil managed
{
.maxstack 4
.locals init (
[0] int32 i,
[1] bool CS$4$0000)
L_0000: nop
L_0001: ldarg.1
L_0002: ldnull
L_0003: ceq
L_0005: ldc.i4.0
L_0006: ceq
L_0008: stloc.1
L_0009: ldloc.1
L_000a: brtrue.s L_0018
L_000c: nop
L_000d: ldstr "buffer"
L_0012: newobj instance void [mscorlib]System.ArgumentNullException::.ctor(string)
L_0017: throw
L_0018: ldc.i4.0
L_0019: stloc.0
L_001a: br.s L_0032
L_001c: nop
L_001d: ldarg.1
L_001e: ldloc.0
L_001f: ldarg.0
L_0020: call instance int32 WindowsFormsApplication1.ClassRandom::InternalSample()
L_0025: ldc.i4 0x100
L_002a: rem
L_002b: conv.u1
L_002c: stelem.i1
L_002d: nop
L_002e: ldloc.0
L_002f: ldc.i4.1
L_0030: add
L_0031: stloc.0
L_0032: ldloc.0
L_0033: ldarg.1
L_0034: ldlen
L_0035: conv.i4
L_0036: clt
L_0038: stloc.1
L_0039: ldloc.1
L_003a: brtrue.s L_001c
L_003c: ret
}
.method public hidebysig newslot virtual instance float64 NextDouble() cil managed
{
.maxstack 1
.locals init (
[0] float64 CS$1$0000)
L_0000: nop
L_0001: ldarg.0
L_0002: callvirt instance float64 WindowsFormsApplication1.ClassRandom::Sample()
L_0007: stloc.0
L_0008: br.s L_000a
L_000a: ldloc.0
L_000b: ret
}
.method family hidebysig newslot virtual instance float64 Sample() cil managed
{
.maxstack 2
.locals init (
[0] float64 CS$1$0000)
L_0000: nop
L_0001: ldarg.0
L_0002: call instance int32 WindowsFormsApplication1.ClassRandom::InternalSample()
L_0007: conv.r8
L_0008: ldc.r8 4.6566128752457969E-10
L_0011: mul
L_0012: stloc.0
L_0013: br.s L_0015
L_0015: ldloc.0
L_0016: ret
}
.field private int32 inext
.field private int32 inextp
.field private static literal int32 MBIG = int32(0x7fffffff)
.field private static literal int32 MSEED = int32(0x9a4ec86)
.field private static literal int32 MZ = int32(0)
.field private int32[] SeedArray
}
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
کروم (Chorme) کلاس:
کد:
ClassRandom = assembly class
{ Fields }
private inext: Int32;
private inextp: Int32;
private const MBIG: Int32 := $7fffffff;
private const MSEED: Int32 := $9a4ec86;
private const MZ: Int32 := 0;
private SeedArray: array of Int32;
{ Methods }
constructor ClassRandom;
begin
constructor(Environment.TickCount);
end;
constructor ClassRandom(Seed: Int32);
begin
inherited constructor;
self.SeedArray := new Int32[$38];
var num2: Int32 := ($9a4ec86 - Math.Abs(Seed));
self.SeedArray[$37] := num2;
var num3: Int32 := 1;
{C# style for loop: }
var i: Int32 := 1;
while (i < $37) do begin
var index: Int32 := (($15 * i) mod $37);
self.SeedArray[index] := num3;
num3 := (num2 - num3);
if (num3 < 0) then
num3 := (num3 + $7fffffff);
num2 := self.SeedArray[index];
inc(i)
end;
{C# style for loop: }
var j: Int32 := 1;
while (j < 5) do begin
{C# style for loop: }
var k: Int32 := 1;
while (k < $38) do begin
self.SeedArray[k] := (self.SeedArray[k] - self.SeedArray[(1 + ((k + 30) mod $37))]);
if (self.SeedArray[k] < 0) then
self.SeedArray[k] := (self.SeedArray[k] + $7fffffff);
inc(k)
end;
inc(j)
end;
self.inext := 0;
self.inextp := $15;
Seed := 1
end;
method ClassRandom.GetSampleForLargeRange: Double;
begin
var num: Int32 := self.InternalSample;
if (iif(((self.InternalSample mod 2) = 0), 1, 0) <> 0) then
num := -num;
var num2: Double := num;
num2 := (num2 + 2147483646);
begin
result := (num2 div 4294967293);
exit
end
end;
method ClassRandom.InternalSample: Int32;
begin
var inext: Int32 := self.inext;
var inextp: Int32 := self.inextp;
if (inc(inext) >= $38) then
inext := 1;
if (inc(inextp) >= $38) then
inextp := 1;
var num: Int32 := (self.SeedArray[inext] - self.SeedArray[inextp]);
if (num < 0) then
num := (num + $7fffffff);
self.SeedArray[inext] := num;
self.inext := inext;
self.inextp := inextp;
begin
result := num;
exit
end
end;
method ClassRandom.Next: Int32;
begin
result := self.InternalSample
end;
method ClassRandom.Next(maxValue: Int32): Int32;
begin
if (maxValue < 0) then
;
begin
result := ((self.Sample * maxValue) as Int32);
exit
end
end;
method ClassRandom.Next(minValue: Int32; maxValue: Int32): Int32;
begin
if (minValue > maxValue) then
;
var num: Int64 := (maxValue - minValue);
if (num <= $7fffffff) then
begin
result := (((self.Sample * num) as Int32) + minValue);
exit
end;
begin
result := ((((self.GetSampleForLargeRange * num) as Int64) as Int32) + minValue);
exit
end
end;
method ClassRandom.NextBytes(buffer: array of Byte);
begin
if (buffer = nil) then
raise new ArgumentNullException('buffer');
{C# style for loop: }
var i: Int32 := 0;
while (i < buffer.Length) do begin
buffer[i] := ((self.InternalSample mod $100) as Byte);
inc(i)
end
end;
method ClassRandom.NextDouble: Double;
begin
result := self.Sample
end;
method ClassRandom.Sample: Double;
begin
result := (self.InternalSample * 4.6566128752457969E-10)
end;
end;
با تشکر از همراهی شما. قربان همه شما یا فعلا یا علی:11:.