title: C# Array/Random Image Help for Memory Game
body: <p>I am trying to create a game, where the user will see an image, then go to the next page and need to click on that same image. Kind of a memory game. The problem I am having is randomly sorting the array, and being able to determine which image they clicked. On my page I have five images that are randomly populated and a submit button. I would ideally like it to check to make sure they selected one, and then compare it with what is the program selected one (in this example im not using post or anything for simplicity. I can easily code that so I just need to figure out why this doesnt work) Right now I am just randomly picking a value and then try to determine if the user clicked that same one. But I get mixed results sometimes I get the same number in my selvalue and programvalue variables. Can anyone help me? I a coding in c#</p>
  
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
          if (!Page.IsPostBack)
              {
                  Random random = new Random();
                  List&lt;string&gt; urls = new List&lt;string&gt; { };
                  List&lt;int&gt; nums = new List&lt;int&gt; { };
                  List&lt;string&gt; iconnames = new List&lt;string&gt; 
                      {
                          "images/verimage1.png", 
                          "images/verimage2.png", 
                          "images/verimage3.png", 
                          "images/verimage4.png", 
                          "images/verimage5.png" 
                      };
                  int noiconlabel = random.Next(iconnames.Count);
                  switch (noiconlabel)
                  {
                      case 0:
                          {
                              iconnamelabel.Text = "Newspaper";
                              HiddenField2.Value = "1";
                              break;
                          }
                      case 1:
                          {
                              iconnamelabel.Text = "iPod";
                              HiddenField2.Value = "2";
                              break;
                          }
                      case 2:
                          {
                              iconnamelabel.Text = "Star";
                              HiddenField2.Value = "3";
                              break;
                          }
                      case 3:
                          {
                              iconnamelabel.Text = "Lock";
                              HiddenField2.Value = "4";
                              break;
                          }
                      case 4:
                          {
                              iconnamelabel.Text = "Die";
                              HiddenField2.Value = "5";
                              break;
                          }
                  }
                  for (int a = 0; a &lt; 5; a++)
                  {
                      int index = random.Next(iconnames.Count);
                      var name = iconnames[index];
                      urls.Add(name);
                      nums.Add(index + 1);
                      iconnames.RemoveAt(index);
                  }
  
                  Image1.ImageUrl = urls[0];
                  Image1.CommandArgument = nums[0].ToString();
                  Image2.ImageUrl = urls[1];
                  Image2.CommandArgument = nums[1].ToString();
                  Image3.ImageUrl = urls[2];
                  Image3.CommandArgument = nums[2].ToString();
                  Image4.ImageUrl = urls[3];
                  Image4.CommandArgument = nums[3].ToString();
                  Image5.ImageUrl = urls[4];
                  Image5.CommandArgument = nums[4].ToString();
  
              }
      }
  
      protected void Image1_Click(object sender, ImageClickEventArgs e)
      {
          ImageButton img = (ImageButton)(sender);
          HiddenField1.Value = img.CommandArgument;
  
      }
  
      protected void Image2_Click(object sender, ImageClickEventArgs e)
      {
          ImageButton img = (ImageButton)(sender);
          HiddenField1.Value = img.CommandArgument ;
      }
  
      protected void Image3_Click(object sender, ImageClickEventArgs e)
      {
          ImageButton img = (ImageButton)(sender);
          HiddenField1.Value = img.CommandArgument;
      }
  
      protected void Image4_Click(object sender, ImageClickEventArgs e)
      {
          ImageButton img = (ImageButton)(sender);
          HiddenField1.Value = img.CommandArgument;
      }
  
      protected void Image5_Click(object sender, ImageClickEventArgs e)
      {
          ImageButton img = (ImageButton)(sender);
          HiddenField1.Value = img.CommandArgument;
      }
  
      protected void Button1_Click(object sender, EventArgs e)
      {
          string selvalue = HiddenField1.Value;
          string programvalue = HiddenField2.Value;
  
          if (selvalue == null | selvalue == "")
          {
              errorverlabel.Text = "&lt;span style='color: red; font-size: 8pt;'&gt;No Verification Image Selected, Please try again.&lt;/span&gt;";
          }
          else
          {
              if (selvalue != programvalue)
              {
                  errorverlabel.Text = "&lt;span style='color: red; font-size: 8pt;'&gt;Wrong Verification Image Selected, Please try again.&lt;/span&gt;";
              }
          }
      }
  
  }
  </code></pre>