Bytes() public method

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.
return byte[]
Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #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);
        }