Пример #1
0
 static void Main(string[] args)
 {
     byte[] seed;
     if (args.Length > 0)
     {
         string hexSeed = args[0];
         if (hexSeed.Length != 64 || hexSeed.Any(c => !"0123456789abcdef".Contains(c)))
         {
             Console.WriteLine("Invalid seed value (expected 64 hex characters)");
             return;
         }
         seed = BinaryUtils.StringToByteArray(hexSeed);
     }
     else
     {
         seed = BinaryUtils.GenerateSeed(Environment.TickCount);
     }
     try
     {
         var random  = new Xoshiro256Plus();
         var factory = new ProgramFactory(ProgramOptions.FromXml(), random);
         var p       = factory.GenProgram(seed);
         p.WriteTo(Console.Out);
         Console.WriteLine($"// {random.Counter} random numbers used");
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Пример #2
0
        public static unsafe byte[] GenerateSeed(long init)
        {
            ulong smallSeed = (ulong)init;

            byte[] bigSeed = new byte[4 * sizeof(ulong)];
            fixed(byte *buffer = bigSeed)
            {
                ulong *s = (ulong *)buffer;

                s[0] = Xoshiro256Plus.SplitMix64(ref smallSeed);
                s[1] = Xoshiro256Plus.SplitMix64(ref smallSeed);
                s[2] = Xoshiro256Plus.SplitMix64(ref smallSeed);
                s[3] = Xoshiro256Plus.SplitMix64(ref smallSeed);
            }

            return(bigSeed);
        }