Ejemplo n.º 1
0
        public byte[] GetRandomData(int dataSize, int bytesDoneToRaiseEvent)
        {
            if (dataSize < bytesDoneToRaiseEvent)
            {
                throw new InvalidOperationException();
            }
            if (bytesDoneToRaiseEvent <= 0)
            {
                throw new InvalidOperationException();
            }

            var random = new Random();

            byte[] result = new byte[dataSize];
            byte[] pack   = new byte[bytesDoneToRaiseEvent];

            int fullPacksCount = dataSize / bytesDoneToRaiseEvent;
            int lastPackSize   = dataSize % bytesDoneToRaiseEvent;

            for (int i = 0; i < fullPacksCount; i++)
            {
                random.NextBytes(pack);
                pack.CopyTo(result, i * bytesDoneToRaiseEvent);

                RandomDataGenerated?.Invoke((i + 1) * bytesDoneToRaiseEvent, dataSize);
            }

            if (lastPackSize > 0)
            {
                random.NextBytes(pack);
                Array.Copy(pack, 0, result, fullPacksCount * bytesDoneToRaiseEvent, lastPackSize);
            }

            RandomDataGenerationDone.Invoke(this, EventArgs.Empty);

            random.NextBytes(result);
            return(result);
        }
Ejemplo n.º 2
0
 protected virtual void OnRandomDataGenerationDone(object sender, EventArgs e)
 {
     RandomDataGenerationDone?.Invoke(sender, e);
 }
Ejemplo n.º 3
0
 protected virtual void OnRandomGeneration(object bytesDone, RandomEventArgs totalBytes)
 {
     RandomDataGenerationDone?.Invoke(bytesDone, totalBytes);
 }