title: How to suspend execution for a random amount of time at random intervals
body: <p>I'm back again ... already.</p>
  
  <p>As the second part to my program, I need to be able to pause my program at random intervals - for example, 10 minutes into the program it gets paused for 20 seconds, 47 minutes in it gets paused for 3 minutes 49 milliseconds ... something like that. I'm not going to attempt a shot at this yet as all the stuff I've found seems to be way too complicated for my tiny little brain to understand, so if someone could break it down for me, that would be great.</p>
  
  <p>Below is my code, I need to pause the bit in the for loop. Thanks!
  Also, I do know that I've got it clicking, sleeping, clicking, sleeping and then repeating the loop - I want it like that :)</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Threading;
  using System.Runtime.InteropServices;
  
  namespace MagicMouse
  {
      public partial class Form1 : Form
      {
          //all this stuff has to do with being able to actually click a mouse
          //[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
          //public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
  
          [DllImport("user32.dll")]
          public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
          private const int MOUSEEVENTF_LEFTDOWN = 0x02;
          private const int MOUSEEVENTF_LEFTUP = 0x04;
          private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
          private const int MOUSEEVENTF_RIGHTUP = 0x10;
  
          //this function will click the mouse using the parameters assigned to it
          public void DoMouseClickLeft()
          {
              //Call the imported function with the cursor's current position
              int X = Cursor.Position.X;
              int Y = Cursor.Position.Y;
              mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
          }
  
          public void NumberCheck(string ValidateNum)
          {
              long CanConvertOut = 0;
              bool CanConvertBool = long.TryParse(ValidateNum, out CanConvertOut);
              if (CanConvertBool == false)
              {
                  MessageBox.Show("Please enter a valid number.");
                  return;
              }
          }
  
          //this generates the random number used for sleep timer
          private int RandomNumber(int min, int max)
          {
              Random random = new Random();
              return random.Next(min, max);
          }
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
          }
  
          //button 1 is start clicking
          private void button1_Click(object sender, EventArgs e)
          {
              //this section sends data to the number validation function
              string ValidateNum = NumberOfItems.Text;
              NumberCheck(ValidateNum);
              int Clicks = Convert.ToInt16(NumberOfItems.Text);
  
              for (int i = 1; i &lt; Clicks; i++)
              {
                  int SleepTime1 = RandomNumber(819, 1092);
                  DoMouseClickLeft();
                  Thread.Sleep(SleepTime1);
                  DoMouseClickLeft();
                  Thread.Sleep(SleepTime1);
              }
          }
  
          //button 2 is exit
          private void button2_Click(object sender, EventArgs e)
          {
              Application.Exit();
  
          }
  
  
      }
  }
  </code></pre>