Bytes() public méthode

Draw an array of random and uniform bytes. Thread-safe if Byte() is thread-safe.
public Bytes ( int length ) : byte[]
length int The array length requested.
Résultat byte[]
        /// <summary>
        /// Seed with random bytes from another RNG.
        /// </summary>
        public void Seed(Random rand)
        {
            UInt32[] seed = new UInt32[SeedLength];

            for (int i = 0; i < seed.Length; i++)
            {
                byte[] b = rand.Bytes(4);
                seed[i] = BitConverter.ToUInt32(b, 0);
            }

            Seed(seed);
        }
        /// <summary>
        /// Seed with random bytes from another RNG.
        /// </summary>
        public void Seed(Random rand)
        {
            UInt32[] seed = new UInt32[SeedLength];

            for (int i = 0; i < seed.Length; i++)
            {
                byte[] b = rand.Bytes(4);
                seed[i] = BitConverter.ToUInt32(b, 0);
            }

            Seed(seed);
        }
Exemple #3
0
        /// <summary>
        /// Draw an array of random and uniform bytes.
        /// Use the buffered random bytes if available, otherwise use Fallback RNG.
        /// </summary>
        /// <param name="length">The array length requested.</param>
        public override byte[] Bytes(int length)
        {
            byte[] arr;

            if (IsAvailableBytes(length))
            {
                arr = new byte[length];

                for (int i = 0; i < length; i++)
                {
                    arr[i] = Queue.Dequeue();
                }
            }
            else
            {
                arr = RandFallback.Bytes(length);
            }

            return(arr);
        }