artech 0 Newbie Poster

Hi all,

I'm looking for some direction in how to approach this problem.

$arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);

I need to create a second array using the values in the first array in a random order, without repeating or omitting any of the values, except one of them.

I'm having such a hard time with this next part, and I even struggle to explain it. So please clarify as needed.

I need to fill the second array with a random combination of the first array, with one value repeated. But the value that is repeated has to be randomly selected from the first five positions of the new array, and it has to be placed randomly into one of the last five positions of the new array.

so assuming that the first five values of the randomly generated array are:
3, 7, 8, 19, 14

I would need to continue randomly filling the 2nd array with values from the first array ($arr, above) until I fill position 15 (the 16th value). Then positions 16-20 (17th through 21st values) need to have the 4 remaining numbers and one of the numbers from the first five spots (3, 7, 8, 19, or 14 in this example).

So that the final array would look something like this

$arr2 = array(
0 => 3,
1 => 7,
2 => 8,
3 => 19,
*4 => 14,

5 => 1, 6=>2, 7=>4, 8=>20, 9=>18, 10=>16, 11=>15, 12=>12, 13=>11, 14=>6, 15=>10,

16 => 17,
17 => 5,
*18 => 14,
19 => 9,
20 => 13);

I've indicated the repeated number with an asterisk and have used position => value nomenclature hoping for clarity.

In this case the value in position 4 is repeated in position 18.

I need this part randomly figured out during each iteration in addition to randomly filling all the original values contained in the first array. So the example above would be only one possible outcome.

Thanks in advance for any guidance you can provide. Please let me know if what I'm asking is not clear and I will try to clarify as needed.