示例#1
0
        public image_sol(string filename, SharpDX.Direct2D1.RenderTarget d2d_render_target)
        {
            path = filename;

            System.Security.Cryptography.RandomNumberGenerator rng = System.Security.Cryptography.RandomNumberGenerator.Create();
            byte[] arr = new byte[16];
            rng.GetNonZeroBytes(arr);

            rand = new Random(BitConverter.ToInt32(arr, 0));
            rng.Dispose();
            points_count = 0;


            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    BitmapFrame bmpFrame = BitmapFrame.Create(fs);
                    width  = bmpFrame.PixelWidth;
                    height = bmpFrame.PixelHeight;
                }
            }
            catch
            {
                width  = 200;
                height = 100;
                path   = "invalid";
            }
            bitmap = LoadFromFile(d2d_render_target, path);
            ipts   = new List <IPoint>();
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _rng.Dispose();
     }
     base.Dispose(disposing);
 }
示例#3
0
        private int SecureRandomInt(int min, int max)
        {
            secureRand = System.Security.Cryptography.RandomNumberGenerator.Create();

            //Store bytes of an integer
            byte[] bytes = new byte[4];
            //Generate bytes through the cryptographically secure RNG
            secureRand.GetBytes(bytes);

            //Convert the bytes we got to UInt32
            UInt32 scale = BitConverter.ToUInt32(bytes, 0);

            secureRand.Dispose();
            //Calculate the number between min and max inclusive
            return((int)(min + (max - min) * (scale / (uint.MaxValue + 1.0))));
        }
示例#4
0
 public void FillBuffer()
 {
     if (IsLinux)
     {
         FileStream fs = File.OpenRead("/dev/random");
         for (int i = 0; i < bufferSize; i++)
         {
             buffer[i] = (byte)fs.ReadByte();
         }
         fs.Close();
     }
     else
     {
         if (rng == null)
         {
             rng = System.Security.Cryptography.RandomNumberGenerator.Create();
         }
         rng.GetBytes(buffer);
         rng.Dispose();
     }
     bufferIndex = 0;
 }