1 formato de texto
usando Sistema;
namespace Legalsoft.Truffer
{ /// <summary> /// Generador aleatorio de alta calidad que utiliza solo aritmética de 32 bits. Las mismas convenciones /// que Ran.Period es 3.11E37. Recomendado sólo cuando la aritmética de 64 bits no está /// disponible. /// </summary> clase pública Ranlim32 { privado uint u { get; colocar; } uint privado v { get; colocar; } = 0x85ca18e3; // 0x85ca18e3=2244614371; uint privado w1 {obtener; colocar; } = 521288629; uint privado w2 {obtener; colocar; } = 362436069;
público Ranlim32 (uint j)
{ this.v = 2244614371U; this.w1 = 521288629U; this.w2 = 362436069U; u = j^v; int32(); v = tu; int32(); }
público uint int32()
{ tu = tu * 2891336453U + 1640531513U; v ^= v >> 13; v^= v<< 17; v ^= v >> 5; w1 = (uint)(33378 * (w1 & 0xffff) + (w1 >> 16)); w2 = (uint)(57225 * (w2 & 0xffff) + (w2 >> 16)); uint x = u ^ (u << 9); x ^= x >> 17; x ^= x << 6; uint y = w1 ^ (w1 << 17); y ^= y >> 15; y ^= y << 5; devolver (x + v) ^ (y + w2); }
doble duda pública()
{ doble r = 2.32830643653869629E-10 * int32(); retorno (r < 0,0)? (1 + r): r; }
public double truedoub()
{ return 2.32830643653869629E-10 * (int32() + 2.32830643653869629E-10 * int32()); } } }
2 formato de código
using System;
namespace Legalsoft.Truffer
{
/// <summary>
/// High-quality random generator using only 32-bit arithmetic.Same conventions
/// as Ran.Period is 3.11E37 . Recommended only when 64-bit arithmetic is not
/// available.
/// </summary>
public class Ranlim32
{
private uint u { get; set; }
private uint v { get; set; } = 0x85ca18e3; // 0x85ca18e3=2244614371;
private uint w1 { get; set; } = 521288629;
private uint w2 { get; set; } = 362436069;
public Ranlim32(uint j)
{
this.v = 2244614371U;
this.w1 = 521288629U;
this.w2 = 362436069U;
u = j ^ v; int32();
v = u; int32();
}
public uint int32()
{
u = u * 2891336453U + 1640531513U;
v ^= v >> 13;
v ^= v << 17;
v ^= v >> 5;
w1 = (uint)(33378 * (w1 & 0xffff) + (w1 >> 16));
w2 = (uint)(57225 * (w2 & 0xffff) + (w2 >> 16));
uint x = u ^ (u << 9);
x ^= x >> 17;
x ^= x << 6;
uint y = w1 ^ (w1 << 17);
y ^= y >> 15;
y ^= y << 5;
return (x + v) ^ (y + w2);
}
public double doub()
{
double r = 2.32830643653869629E-10 * int32();
return (r < 0.0) ? (1 + r) : r;
}
public double truedoub()
{
return 2.32830643653869629E-10 * (int32() + 2.32830643653869629E-10 * int32());
}
}
}