namespace RandomClass
{
public class XorShift
{
private uint x, y, z, w;
///
/// XorShiftクラスの初期化
///
/// シード値
public XorShift(uint seed = 88675123U)
{
x = 123456789U;
y = 362436069U;
z = 521288629U;
w = seed;
}
///
/// 0~2^32-1の範囲の乱数を生成
///
/// 0~2^32-1の範囲の乱数
public uint Rand()
{
uint t = x ^ (x > 19)) ^ (t ^ (t >> 8));
return w;
}
///
/// 指定範囲の乱数を生成する
///
/// 最小値
/// 最大値
/// 指定範囲の乱数
public uint RandRange(int min, int max)
{
uint value = Rand();
return (uint)min + value % ((uint)(max - min));
}
}
}
C#でも「XorShift乱数生成アルゴリズム」を書いてみた
C#でも「XorShift乱数生成アルゴリズム」を書いてみた
C#でも「XorShift」乱数生成アルゴリズム」を書いてみました(前回のC言語のプログラムをC#にしただけです)。Visual C#はシフト演算が使えるのでC言語同様に書くことができます。
最後に編集したユーザー naohiro19 on 2016年5月04日(水) 22:57 [ 編集 2 回目 ]
コメントはまだありません。