title: Randomize game objects actions, so they won't happen at the same time
body: <p>I wrote a script that change states for my NPCs. I run a function that return either true or false. if it is true, the NPC change state.</p>
  
  <p>All is fine, except that I see more than one NPC acting exactly at the same time, which look horrible. Feels like they are a military squadron, perfectly synced.</p>
  
  <p>I use a random value to check if the function should return true or false...but I was expecting to see different results for each NPC, since the random value is in place</p>
  
  <pre><code>class void NPCState()
  {
  
      private System.Random rnd = new System.Random();
      private string state;    
  
      Void Start()
      {
          state = "state1";
          StartCoroutine("RunAction");
      }
  
      IEnumerator RunAction()
      {
          ...do stuff every N cycles
          switch (state)
          {  
              case "state1":
                  ... go to state 1                
                  break;
              case "state2":
                  ... go to state 2
                  break;
          }
      }  
  
      void State1()
      {
          ... execute certain tasks
          if (ChangeActionType)
          {
               ...change to a different action type
               state = state2;
          }
      }
  
      void State2()
      {
          ... execute certain tasks
          ... then go back to previous task
          state = state1;
      }
  
      private bool ChangeActionType()
      {
          if (rnd.next(100) &gt; 50)
              return true;
          else
              return false;
      }
  }
  </code></pre>
  
  <p>I did simplify the code to show the part where the state change; and this is basically happening at the same exact time for multiple NPC.</p>
  
  <p>How can I create enough variety in a script, so each NPC may update at random time? I just want to avoid that they will all act like synchro swimmers :)</p>