Другие языки программирования и технологии

Генератор случайных чисел на VS C++

Напишите плз простой код генератора, без особых заморочек)))))))
ПСЕВДОслучайных, попрошу.
Алибек Амренов
Алибек Амренов
52 593
[Serializable, ComVisible(true)]
public __gc class Random
{
// Methods
public: Random() : this(Environment::TickCount)
{
}

public: Random(Int32 __gc* Seed)
{
this->SeedArray = __gc new Int32 __gc*[56];
Int32 __gc* num2 = (161803398 - Math::Abs(Seed));
this->SeedArray[55] = num2;
Int32 __gc* num3 = 1;
for (Int32 __gc* i = 1; (i < 55); i++)
{
Int32 __gc* index = ((21 * i) % 55);
this->SeedArray[index] = num3;
num3 = (num2 - num3);
if (num3 < 0)
{
num3 += 2147483647;
}
num2 = this->SeedArray[index];
}
for (Int32 __gc* j = 1; (j < 5); j++)
{
for (Int32 __gc* k = 1; (k < 56); k++)
{
this->SeedArray[k] -= this->SeedArray[(1 + ((k + 30) % 55))];
if (this->SeedArray[k] < 0)
{
this->SeedArray[k] += 2147483647;
}
}
}
this->inext = 0;
this->inextp = 21;
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 >= 56)
{
inext = 1;
}
if (++inextp >= 56)
{
inextp = 1;
}
Int32 __gc* num = (this->SeedArray[inext] - this->SeedArray[inextp]);
if (num < 0)
{
num += 2147483647;
}
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)
{
throw __gc new ArgumentOutOfRangeException(S"maxValue", String::Format(CultureInfo::CurrentCulture, Environment::GetResourceString(S"ArgumentOutOfRange_MustBePositive"), __gc new Object __gc*[1] {
S"maxValue"}));
}
return *static_cast<__box>((this->Sample() * maxValue));
}

public: virtual Int32 __gc* Next(Int32 __gc* minValue, Int32 __gc* maxValue)
{
if (minValue > maxValue)
{
throw __gc new ArgumentOutOfRangeException(S"minValue", String::Format(CultureInfo::CurrentCulture, Environment::GetResourceString(S"Argument_MinMaxValue"), __gc new Object __gc*[2] {
S"minValue", S"maxValue"}));
}
Int64 __gc* num = (maxValue - minValue);
if (num <= 2147483647)
{
return (*static_cast<__box>((this->Sample() * num)) + minValue);
}
return (*static_cast<__box>(*static_cast<__box>((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 = *static_cast<__box>((this->InternalSample() % 256));
}
}

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 = 2147483647;
private: const Int32 __gc* MSEED = 161803398;
private: const Int32 __gc* MZ = 0;
private: Int32 __gc* SeedArray __gc [];
};
Антон Мордовин
Антон Мордовин
50 492
Вот, например
http ://algolist. manual. ru/maths/generator/lequer .php (без пробелов)