var file = new FileStream("random.txt", FileMode.Create);
var random = new Random();
for (int i = 0; i < 100000000; i++)
{
var bytesToWrite = BitConverter.GetBytes(random.Next(int.MaxValue));
file.Write(bytesToWrite, 0, bytesToWrite.Length);
}
file.Close();
when you simply add some random number to text file
then compressed it get bigger, or it will remain as the same size as the text one
any one know how or why this happened?
Text files tend to compress nicely because they use the same data over and over. Adding some random numbers to the file makes the file less regular, so most compression algorithms will have a harder time compressing the file as much.
Read up on compression algorithms for a better understanding of this. https://en.wikipedia.org/wiki/File_compression