Set Buttons' Background randomly from array of images
<pre><code>else if (setIndexPath == 4)
{
    viewWithButtons.frame = CGRectMake(5, 40, 310, 390);

    int ch = 6;
    int cv = 6;

    for ( int i = 0 ; i &lt; cv ; ++i )
    {
        for ( j = 0 ; j &lt; ch ; ++j )
        {
            btnMatrix = [[[UIButton alloc] initWithFrame:CGRectMake(10+pw*j, 51+ph*i, width, height)] autorelease];
            btnMatrix.tag = i*ch+j;
            btnMatrix.userInteractionEnabled = TRUE;
            [btnMatrix addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchDown];
            [btnMatrix setBackgroundImage:imgDefaultBG forState:UIControlStateNormal];

            [viewWithButtons addSubview:btnMatrix];

            [arrButton addObject:btnMatrix];
        }
    }
}
[self.view addSubview:viewWithButtons];
</code></pre>

<p>I am generating buttons dynamically according to the selected matrix, like 4 * 4, 4 * 5, 4 * 6, 5 * 6, 6 * 6 etc....</p>

<p>Buttons are completely set as per the selected matrix from above (the code is for 6 * 6 matrix).</p>

<p>Now i have to set random background images of these buttons.</p>

<p>I am not able to set this kind of dynamic buttons' background.</p>

<p>is there any effective way to set backgrounds dynamically in random order for each separate buttons?</p>

<pre><code>    for (intimg = 1; intimg &lt;= 15; intimg++)
    {
        arr_FirstSet = [[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:@"%d_f_2.png",intimg], nil];
    }
    for (intimgSET2 = 1; intimgSET2 &lt;= 15; intimgSET2++) {
        arr_SecondSet = [[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:@"%d_s_2.png",intimgSET2], nil];
    }
</code></pre>

<p>I am adding images in this format to the NSMutableArray.</p>

<p>How to pick random image from the above used arrays. I have to match both arrays images &amp; give the result on buttons. If both matches, suppose i press on one button it will display 1_f_2.png  &amp; on another button press it will display 1_s_2.png (as background)then both of these buttons will be removed from the view.</p>

<p>I had tried many logics to get this.</p>

<p>I am not getting exactly what i am interested to do on touchdown of button.</p>

<p>Please suggest any code snippet or link or code also.</p>

<p>Thanks in advance.</p>
