Try the Random.NextBytes
method https://docs.microsoft.com/en-us/dotnet/api/system.random.nextbytes?view=netframework-4.7.2
private byte[] GetByteArray(int sizeInKb)
{
Random rnd = new Random();
byte[] b = new byte[sizeInKb * 1024]; // convert kb to byte
rnd.NextBytes(b);
return b;
}
If you need cryptographically safe random bytes, use System.Security.Cryptography.RNGCryptoServiceProvider
instead.
7
solved How to create byte array and fill it with random data [duplicate]