title: How can I generate random text file with random content and size?
body: <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace Tests
  {
      class RandomTests
      {
          private static Random random = new Random();
          public static string RandomString(int length)
          {
              const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
              return new string(Enumerable.Repeat(chars, length)
                .Select(s =&gt; s[random.Next(s.Length)]).ToArray());
          }
  
          static List&lt;string&gt; listv;
          public static void GenerateRandomStrings()
          {
              for (int i = 0; i &lt; random.Next(20, 1000); i++)
              {
                  string rand = RandomString(20);
                  ListViewCostumControl.lvnf.Items.Add(rand);
              }
  
              listv = ListViewCostumControl.lvnf.Items.Cast&lt;ListViewItem&gt;()
                                   .Select(item =&gt; item.Text)
                                   .ToList();
          }
  
          private void UsageExample()
          {
              GenerateRandom(5, 1, 6);
          }
  
          public static List&lt;int&gt; GenerateRandom(int count)
          {
              return GenerateRandom(count, 0, Int32.MaxValue);
          }
  
          // Note, max is exclusive here!
          public static List&lt;int&gt; GenerateRandom(int count, int min, int max)
          {
  
              //  initialize set S to empty
              //  for J := N-M + 1 to N do
              //    T := RandInt(1, J)
              //    if T is not in S then
              //      insert T in S
              //    else
              //      insert J in S
              //
              // adapted for C# which does not have an inclusive Next(..)
              // and to make it from configurable range not just 1.
  
              if (max &lt;= min || count &lt; 0 ||
                      // max - min &gt; 0 required to avoid overflow
                      (count &gt; max - min &amp;&amp; max - min &gt; 0))
              {
                  // need to use 64-bit to support big ranges (negative min, positive max)
                  throw new ArgumentOutOfRangeException("Range " + min + " to " + max +
                          " (" + ((Int64)max - (Int64)min) + " values), or count " + count + " is illegal");
              }
  
              // generate count random values.
              HashSet&lt;int&gt; candidates = new HashSet&lt;int&gt;();
  
              // start count values before max, and end at max
              for (int top = max - count; top &lt; max; top++)
              {
                  // May strike a duplicate.
                  // Need to add +1 to make inclusive generator
                  // +1 is safe even for MaxVal max value because top &lt; max
                  if (!candidates.Add(random.Next(min, top + 1)))
                  {
                      // collision, add inclusive max.
                      // which could not possibly have been added before.
                      candidates.Add(top);
                  }
              }
  
              // load them in to a list, to sort
              List&lt;int&gt; result = candidates.ToList();
  
              // shuffle the results because HashSet has messed
              // with the order, and the algorithm does not produce
              // random-ordered results (e.g. max-1 will never be the first value)
              for (int i = result.Count - 1; i &gt; 0; i--)
              {
                  int k = random.Next(i + 1);
                  int tmp = result[k];
                  result[k] = result[i];
                  result[i] = tmp;
              }
              return result;
          }
      }
  }
  </code></pre>
  
  <p>For now I'm using only the GenerateRandomStrings() in Form1.
  but now I ant to generate random text files with random content and size.
  for example 100MB or 100GB files sizes with random content.</p>
  
  <p>The files sizes should be from bytes to giga bytes. can be 1b file or 100GB file.</p>
  
  <p>and then add the files to the listview as items like doing in the GenerateRandomStrings() function.</p>
  
  <pre><code>ListViewCostumControl.lvnf.Items.Add(rand);
  </code></pre>
  
  <p>the same idea to add generated text files with random content and sizes.</p>