title: Random Movement of a Character in a matrix
body: <p>Im trying to create a program that shows a character matrix 10x10, and shows a character in it, and in every 600 miliseconds the character would move randomly. But my problem is that everytime i run the program, it is the same movement.</p>
  
  <p>If you look at the function Random_move i used the function Rand()... i also tried with srand(time(null)); before, but that only makes both characters, a and b, to move always in the same direction. Can someone please help.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  #include &lt;time.h&gt;
  using namespace std;
  
  class mapa
  {
      private :
      char map[10][10];
      char background[10][10];
      public :
      mapa();
      void cpy_btom();
      void copy_to_map(int, int, char);
      void print();
  };
  class character
  {
      private :
      int posx;
      int posy;
      char type;
      public :
      character(char,int,int);
      void send_print(mapa &amp;);
      void random_move(mapa &amp;);
      void delay(int);
  };
  
  int main()
  {
      character C1('A', 5, 5);
      character C2('B', 8, 2);
      mapa Mapa;
      while(!GetAsyncKeyState(VK_ESCAPE))
      {
          Mapa.print();
  
          C1.delay(750);
  
          C1.random_move(Mapa);
          C2.random_move(Mapa);
      }
  }
  
  void mapa :: cpy_btom()
  {
      for(int a = 0;a &lt; 10;a++)
      {
          for(int b = 0;b&lt;10;b++)
          {
              map[a][b] = background[a][b];
          }
      }
  }
  void mapa :: print()
  {
      system("cls");
  
      for(int a = 0;a&lt;10;a++)
      {
          for(int b = 0;b&lt;10;b++)
          {
              cout &lt;&lt; map[a][b];
          }
          cout &lt;&lt; endl;
      }
      cpy_btom();
  }
  character :: character(char kind = 'a', int x = 5, int y = 5)
  {
      type = kind;
      posx = x;
      posy = y;
  }
  void character :: send_print(mapa &amp; mapa)
  {
      mapa.copy_to_map(posx, posy, type);
  }
  
  void character :: random_move(mapa &amp; MAP)
  {
  
      int a = rand() % 5;
      int b = rand() % 50;
      if(a == 0) //x --
      {
          if(b &lt; 45)
          {
              if(posx &gt; 0)
                  posx--;
          }
          else
          {
              if(posx &gt; 1)
              posx = posx - 2;
          }
      }
      else if(a == 1)
      {
          if(b &lt; 45)
          {
              if(posx &lt; 10)
              posx++;
  
          }
          else
          {
              if(posx &lt; 9)
              posx = posx + 2;
          }
      }
      else if(a == 2)
      {
          if(b &lt; 45)
          {
              if(posy &gt; 0)
              posy--;
          }
          else
          {
              if (posy &gt; 1)
              posy = posy - 2;
          }
      }
      else if(a == 3)
      {
          if(b &lt; 45)
          {
              if(posy &lt; 10)
              posy++;
          }
          else
          {
              if(posy &lt; 9)
              posy = posy + 2;
          }
      }
      send_print(MAP);
  }
  
  void character :: delay(int time)
  {
      int a = clock();
      int b = clock() + time;
      while(a &lt; b)
      {
          a = clock();
      }
  }
  mapa :: mapa()
  {
      for(int a = 0;a &lt; 10;a++)
      {
          for(int b = 0;b &lt; 10;b++)
          {
              map[a][b] = ' ';
              background[a][b] = ' ';
          }
      }
  }
  
  void mapa :: copy_to_map(int x, int y, char kind)
  {
      map[x][y] = kind;
  }
  </code></pre>