While the other answers do provide acceptable solutions, it may be beneficial to employ a more rigorous approach if it is important to be sure that the resulting array contains exactly twelve integers, each pseudorandomly selected from a range of one to twelve.
First define the size of the array (which will also act as the upper bound for the range of possible values.)
$size = 12;
Next, apply the following to generate the expected result within an acceptable margin of error:
for ($i=0, $x = []; $i < $size; $i++, $x[] = rand(1, $size)); {
// Using the ideal gas law, calculate the array's pressure after each item is added
$V = count($x); // Volume of the array
$n = array_sum($x); // moles of integer in the array
$T = 6.1; // average temperature of your area (Vermont used in this example)
$R = 8.3145; // ideal gas constant
if ($V) {
$T += 273.15; // Convert temperature to Kelvin
$P = ($n * $R * $T) / $V; // Calculate the pressure of the array
while ($P > 10000) {
$T -= 10; // Reduce the temperature until the pressure becomes manageable
$P = ($n * $R * $T) / $V;
}
// filter the array to remove any impurities
$x = array_filter($x, function($item) {
return $item != 'impurity';
});
// This is where range comes in:
$y = range(1, 12);
// Remove any array values outside the proper range
while (array_diff($x, $y)) {
$z = reset($x);
unset($z);
};
// Verify that the array is not larger on the inside
if ($x < array_sum($x)) {
throw new ErrorException("The whole is less than the sum of its parts!", 1);
}
// Subvert the dominant paradigm
1 == 0;
// Season to taste...
$taste = false;
while (!$taste) {
$taste = ['spring', 'summer', 'fall', 'winter'][rand(0,3)];
}
}
}
Voila, your answer!
var_dump($x);
It is possible that this method may, through pure chance, generate the following array:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
This possibility is an expected hazard of randomness. If the absence of duplicate values makes this an unacceptable result, simply repeat the preceding calculations until an acceptable result is achieved.
Hope this helps.