예제 #1
0
        private static void DrawImage(int width, int height, string path)
        {
            using (var prng = RNGVenturaProviderFactory.CreateSeeded())
            {
                int length = width * height;

                var data = new byte[length];
                prng.GetBytes(data);

                Color colour;
                int   temp = 0;

                using (Bitmap map = new Bitmap(width, height))
                {
                    for (int i = 0; i < map.Width; i++)
                    {
                        for (int j = 0; j < map.Height; j++)
                        {
                            int rn = data[temp];
                            colour = Color.FromArgb(rn, rn, rn);
                            map.SetPixel(i, j, colour);

                            temp++;
                        }
                    }

                    map.Save(path, ImageFormat.Png);
                }
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            Parser.Default.ParseArguments <RandomNumberOptions, RandomNumberArrayOptions>(args)
            .MapResult(
                (RandomNumberOptions opts) =>
            {
                var stream     = new FileStream(opts.SeedPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                using var prng = RNGVenturaProviderFactory.Create(stream, opts.Cipher, opts.EntropyGroup);

                var rn = prng.Next(opts.Min, opts.Max);
                Console.WriteLine(rn);

                return(0);
            },

                (RandomNumberArrayOptions opts) =>
            {
                var stream = new FileStream(opts.SeedPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                var array  = new int[opts.ArrayLength];

                using var prng = RNGVenturaProviderFactory.Create(stream, opts.Cipher, opts.EntropyGroup);

                array = prng.NextArray(opts.Min, opts.Max, opts.ArrayLength);

                for (int i = 0; i < array.Length; i++)
                {
                    Console.Write(array[i] + " ");
                }

                return(0);
            },

                errs => 1
                );
        }
예제 #3
0
        public void RNG_Sequence_Ending_Numbers_Test()
        {
            var array1 = new int[10];
            var array2 = new int[10];

            using (var prng1 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Aes, ReseedEntropySourceGroup.Local))
            {
                for (int i = 0; i < 10; i++)
                {
                    int num = prng1.Next(1, 10);
                    array1[i] = num;
                }
            }

            using (var prng2 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Aes, ReseedEntropySourceGroup.Local))
            {
                for (int i = 0; i < 10; i++)
                {
                    int num = prng2.Next(1, 10);
                    array2[i] = num;
                }
            }

            Assert.AreNotEqual(array1[new Range(5, 10)], array2[new Range(5, 10)]);
        }
예제 #4
0
        public void RNG_Sequence_Ending_Bytes_Test()
        {
            byte[] array1 = new byte[12];
            byte[] array2 = new byte[12];

            using var prng1 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Aes, ReseedEntropySourceGroup.Full);
            prng1.GetBytes(array1);

            foreach (var b in array1)
            {
                System.Diagnostics.Debug.Write(b + " ");
            }

            System.Diagnostics.Debug.WriteLine("");

            using var prng2 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Aes, ReseedEntropySourceGroup.Full);
            prng2.GetBytes(array2);

            foreach (var b in array2)
            {
                System.Diagnostics.Debug.Write(b + " ");
            }

            System.Diagnostics.Debug.WriteLine("");

            Assert.AreNotEqual(array1[new Range(7, 12)], array2[new Range(7, 12)]);
        }
예제 #5
0
 public static void OutputRandomNumberArray()
 {
     using (var prng = RNGVenturaProviderFactory.Create(new MemoryStream()))
     {
         var result = prng.NextArray(0, 1000, 10000);
         Console.WriteLine($"Data generated: {result}");
     }
 }
예제 #6
0
        private double[] GenerateFloatingPointNumberArray()
        {
            double[] array;

            using var prng = RNGVenturaProviderFactory.Create(new MemoryStream());

            array = prng.NextDoubleArray(2, 1000);

            return(array);
        }
예제 #7
0
 public static void OutputRandomNumbers()
 {
     using (var prng = RNGVenturaProviderFactory.Create(new FileStream("seed.bin", FileMode.OpenOrCreate), Cipher.Aes, ReseedEntropySourceGroup.Remote))
     {
         var result = prng.NextArray(1000000, 1000000000, 10000);
         for (int i = 0; i < result.Length; i++)
         {
             Console.WriteLine($"Data generated: {result[i]}");
         }
     }
 }
예제 #8
0
        public void RNGVentura_NextArray_Throws_Exception_For_Negative_Values()
        {
            void Test()
            {
                using var prng = RNGVenturaProviderFactory.Create(new MemoryStream());

                var result = prng.NextArray(-1, 10, 1000);
            }

            Assert.Throws <ArgumentException>(Test);
        }
예제 #9
0
        public void RNGVentura_NextDoubleArray_Throws_Exception_If_Round_To_Decimals_Less_Than_Zero()
        {
            void NegativeTest()
            {
                using var prng = RNGVenturaProviderFactory.Create(new MemoryStream());

                var result = prng.NextDoubleArray(-1, 10);
            }

            Assert.Throws <ArgumentException>(NegativeTest);
        }
예제 #10
0
 private static void TestMethod()
 {
     using (var prng = RNGVenturaProviderFactory.Create(new MemoryStream()))
     {
         for (int i = 0; i <= 10; i++)
         {
             Thread.Sleep(100);
             var data = new byte[1024000];
             prng.GetBytes(data);
             Debug.WriteLine($"Data generated: {i}");
         }
     }
 }
예제 #11
0
        public void RNGVentura_NextDoubleArray_Throws_Exception_If_Length_Zero_Or_Less_Than_Zero()
        {
            void ZeroTest()
            {
                using var prng = RNGVenturaProviderFactory.Create(new MemoryStream());

                var result = prng.NextDoubleArray(2, 0);
            }

            void NegativeTest()
            {
                using var prng = RNGVenturaProviderFactory.Create(new MemoryStream());

                var result = prng.NextDoubleArray(2, -1);
            }

            Assert.Throws <ArgumentException>(ZeroTest);
            Assert.Throws <ArgumentException>(NegativeTest);
        }
예제 #12
0
        public void RNGVentura_NextArray_Throws_Exception_For_Zero_Or_Negative_Array_Length_Values()
        {
            void ZeroTest()
            {
                using var prng = RNGVenturaProviderFactory.Create(new MemoryStream());

                var result = prng.NextArray(1, 10, -1);
            }

            void NegativeTest()
            {
                using var prng = RNGVenturaProviderFactory.Create(new MemoryStream());

                var result = prng.NextArray(1, 10, 0);
            }

            Assert.Throws <ArgumentException>(ZeroTest);
            Assert.Throws <ArgumentException>(NegativeTest);
        }
예제 #13
0
        static void Main(string[] args)
        {
            var output = new byte[16];

            // memory stream, RNG will be seeded automatically and seeds discarded at the end of the operation
            // Cipher by default is AES with full entropy reseed sources
            using var prng = RNGVenturaProviderFactory.Create(new MemoryStream());
            prng.GetBytes(output);

            // uses a file stream to read the seed from file. will write seed to same file at the end of scope
            using var prng2 = RNGVenturaProviderFactory.Create(new FileStream("seed.bin", FileMode.OpenOrCreate));
            prng2.GetBytes(output);

            // support for additional ciphers and reseed entropy sources can be either local, remote or both
            using var prng3 =
                      RNGVenturaProviderFactory.Create(new FileStream("seed.bin", FileMode.OpenOrCreate), Cipher.BlowFish, ReseedEntropySourceGroup.Local);
            prng3.GetBytes(output);

            // seeds the RNG with a combination seed from remote entropy sources - slower than the above options.
            using var prng4 = RNGVenturaProviderFactory.CreateSeeded();
            prng4.GetBytes(output);

            // additional initialisation options
            using var prng5 = RNGVenturaProviderFactory.CreateSeeded(Cipher.Serpent, ReseedEntropySourceGroup.Local);
            prng5.GetBytes(output);

            // special initialisation, creates an instance of RandomNumberGenerator so Ventura can be used as drop-in replacement
            // in solutions that already use RandomNumberGenerator in a source compatible change
            using var prng6 =
                      RNGVenturaProviderFactory.CreateRng(new MemoryStream(), Cipher.Aes, ReseedEntropySourceGroup.Full);
            prng6.GetBytes(output);

            using var prng7 = RNGVenturaProviderFactory.CreateSeeded();
            var num = prng7.Next(1, 10);                // get a 32-bit integer between 1 and 10 both values inclusive

            var numArray = prng7.NextArray(1, 10, 100); // get an array of 100 32-bit integers between 1 and 10 both values inclusive
        }