title: How to populate a file with random numbers?
body: <p>So Basically I am trying to "populate" a file with 10^3 completely random numbers, so I could add them later to a Binary search tree.
  Here is the populate function I worked on so far:</p>
  
  <pre><code>void populateFile(BinarySearchTree b) {
      int random_integer;
      srand( time( NULL ) );
      std::ofstream myfile;
      string line;
      myfile.open ("output.txt");
      myfile &lt;&lt; "Writing this to a file: ";
      for(int index=0; index&lt;1000; index++)
      {
          random_integer = (rand()%1000)+1;
          cout &lt;&lt; random_integer &lt;&lt; endl;
          myfile &lt;&lt; random_integer;
      }
      myfile.close();
  
      int value;
      ifstream file ("output.txt");
      if (file.is_open())
      {
          while ( getline (file,line) )
          {
              value = std::stoi(line);
              b.insert(value);
          }
          myfile.close();
      }
  
      else cout &lt;&lt; "Unable to open file";
  
  }
  </code></pre>
  
  <p>But I cannot seem to write to a file, I can just see the numbers on the console then the program crashes.</p>
  
  <p>My second concern is as follows:
  I want to add those same numbers to a binary search tree. I already have a class and an dd function, but I have no idea how to continue. Then I want to be able to delete them from the BST completely at random.</p>
  
  <p>I already have a remove function written. How is this possible?
  Any ideas will be greatly appreciated.
  P.S: I am fairly new to C++, I am sorry if my questions sounds silly for you. </p>