public XOrShift1024(Span <byte> seed) { if (seed.Length < 128) { throw new Exception($"Not enough seed! 1024 bits = 128 bytes are required"); } this.state = As.uint64(seed).ToArray(); }
static string hexstring <T>(T src, bool zpad = true, bool specifier = true) where T : struct { var digits = string.Empty; var fmt = "X"; if (typeof(T) == typeof(sbyte)) { digits = As.int8(src).ToString(fmt); } else if (typeof(T) == typeof(byte)) { digits = As.uint8(src).ToString(fmt); } else if (typeof(T) == typeof(short)) { digits = As.int16(src).ToString(fmt); } else if (typeof(T) == typeof(ushort)) { digits = As.uint16(src).ToString(fmt); } else if (typeof(T) == typeof(int)) { digits = As.int32(src).ToString(fmt); } else if (typeof(T) == typeof(uint)) { digits = As.uint32(src).ToString(fmt); } else if (typeof(T) == typeof(long)) { digits = As.int64(src).ToString(fmt); } else if (typeof(T) == typeof(ulong)) { digits = As.uint64(src).ToString(fmt); } else if (typeof(T) == typeof(float)) { digits = convert <float, int>(As.float32(src)).ToString(fmt); } else if (typeof(T) == typeof(double)) { digits = convert <double, long>(As.float64(src)).ToString(fmt); } else { throw unsupported <T>(); } var spec = specifier ? "0x" : string.Empty; return(zpad ? (spec + digits.PadLeft(size <T>() * 2, '0')) : (spec + digits)); }