public static class RomuRND32
private static UInt32 xState, yState, zState;
public static void init( UInt32 uX, UInt32 uY, UInt32 uZ ) {
public static UInt32 nextRandom () {
UInt32 xp = xState, yp = yState, zp = zState;
xState = 3323815723u * zp;
yState = yp - xp; yState = RotateLeft(yState,6);
zState = zp - yp; zState = RotateLeft(zState,22);
public static uint RotateLeft(this uint value, int count)
return (value << count) | (value >> (32 - count));
public static class StatsCollector
private static string sGRAPH = "..--::--++xx**!!||()[]%%&&@@$$##";
public static UInt32[] uBits = new UInt32[32];
public static UInt32[] uBytes = new UInt32[256];
public static void collectValue( UInt32 uValue ) {
for ( int iBit = 0; iBit < 32; ++iBit ) {
if ( (uValue & uBit) != 0 ) ++uBits[iBit];
uByte = uValue & 0x000000FF; ++uBytes[uByte]; uValue >>= 8;
uByte = uValue & 0x000000FF; ++uBytes[uByte]; uValue >>= 8;
uByte = uValue & 0x000000FF; ++uBytes[uByte]; uValue >>= 8;
uByte = uValue & 0x000000FF; ++uBytes[uByte];
public static void printStats( int nValues) {
for ( int iBit = 0; iBit < uBits.Length; ++iBit ) {
printGraphLine( String.Format("bit {0:00}", iBit), uBits[iBit], nValues, 80 );
public static void printGraphLine( string sLabel, uint nValue, int nMaxValue, int nWidth ) {
sLine += String.Format( "{0}: {1:000} : ", sLabel, nValue );
decimal dValue = nWidth * ((decimal)nValue / nMaxValue);
int nPips = Decimal.ToInt32(dValue);
for ( int i = 0; i < nPips; ++i ) {
Console.WriteLine( sLine );
public static void Main()
Random rndSeed = new Random();
UInt32 uSeed = (UInt32) rndSeed.Next();
Console.WriteLine("seed = {0:X8}",uSeed);
RomuRND32.init(uSeed,58146387,267884012);
for ( int i = 0; i < nVALUES; ++i ) {
r = RomuRND32.nextRandom();
if ( sOut.Length > 0 ) sOut += ".";
sOut += String.Format("{0:X8}", r);
if ( sOut.Length >= 71 ) { Console.WriteLine( sOut ); sOut = ""; }
StatsCollector.collectValue(r);
Console.WriteLine("bit stats:");
StatsCollector.printStats(nVALUES);