public static byte[] GenerateByteArray(this RandomNumberGenerator generator, int length) { generator.NotNull(nameof(generator)); var buffer = new byte[length]; generator.GetBytes(buffer); return(buffer); }