title: Generating a number on class instantiation
body: <p>I am using OOP to create a basic class and I can't figure how to randomly generate a number for the type of Weapon when each Weapon is instantiated in the main Class.</p>
  
  <pre><code>//Weapon.h
  class Weapon {
  
      int type;
  
  public:
      Weapon();
      ~Weapon();
  
  
      int getType();
  };
  </code></pre>
  
  <p>///////////////////////////////////////////////////////////////////////////////</p>
  
  <pre><code>//Weapon.cpp
  #include "Weapon.h"
  #include &lt;cstdlib&gt;
  #include &lt;time.h&gt;
  
  Weapon::Weapon()
  {
      srand(time(NULL));
      type = rand() % 4;
  }
  
  Weapon::~Weapon() 
  {
  }
  
  int Weapon::getType() {
      return type;
  }
  </code></pre>
  
  <p>///////////////////////////////////////////////////////////////////////////////</p>
  
  <pre><code>//main.cpp
  #include &lt;iostream&gt;
  #include "Weapon.h"
  
  int main() {
  
      Weapon w1, w2, w3;
  
      std::cout &lt;&lt; "w1 is type #" &lt;&lt; w1.getType() &lt;&lt; "\n";
      std::cout &lt;&lt; "w2 is type #" &lt;&lt; w2.getType() &lt;&lt; "\n";
      std::cout &lt;&lt; "w3 is type #" &lt;&lt; w3.getType() &lt;&lt; "\n";
  
      return 0;
  }
  </code></pre>
  
  <p>The results I am getting are:
  "w1 is type #1"
  "w2 is type #1"
  "w3 is type #0"</p>
  
  <p>Everytime I run the program in Visual Studio, the same numbers appear and they aren't being randomized everytime the program runs. How would I achieve this? I seem to have forgotten the basics of c++ because this seems easy to me but I can't figure it out.</p>
  
  <p><strong>EDIT: Using srand in Weapon.cpp, I now get random generation on each run. But all the weapons have the same type value. How would each instantiated weapon have a different type value?</strong></p>