Q:

Generate random value by condition

I've an array: 
$themes = ['class-A', 'class-B','class-C','class-D','class-E','class-F']

And I have the following condition:
I need to generate 12 classes out of that where: 

class-A will occur exactly once or none. 
class-B will occur either 3 or 6 times. 
class-C or class-D has no limit, can occur as many times. 
Class-E  will occur exactly twice or none. 
class-F will occur exactly once or none. 

How can I achieve this? Thanks! 

A:

Another possible implementation 
<?php

$classAPossibleOccuences = [0,1];
$classARandomChosenOccurence = $classAPossibleOccuences[array_rand($classAPossibleOccuences)];

$classBPossibleOccuences = [3,6];
$classBRandomChosenOccurence = $classBPossibleOccuences[array_rand($classBPossibleOccuences)];

$classEPossibleOccuences = [0,2];
$classERandomChosenOccurence = $classEPossibleOccuences[array_rand($classEPossibleOccuences)];

$classFPossibleOccuences = [0,1];
$classFRandomChosenOccurence = $classFPossibleOccuences[array_rand($classFPossibleOccuences)];

$generatedRandomClassesArr = [];

if($classARandomChosenOccurence) {
  $generatedRandomClassesArr[] = 'class-A';
}

if($classFRandomChosenOccurence) {
  $generatedRandomClassesArr[] = 'class-F';
}

for($i = 0; $i < $classBRandomChosenOccurence; $i++) {
  $generatedRandomClassesArr[] = 'class-B';
}

if($classERandomChosenOccurence) {
  for($i = 0; $i < $classERandomChosenOccurence; $i++) {
    $generatedRandomClassesArr[] = 'class-E';
  }
}

while(sizeof($generatedRandomClassesArr) < 12) {
  $randomCOrD = ['C','D'];
  $randomClass = $randomCOrD[array_rand($randomCOrD)];
  $generatedRandomClassesArr[] = 'class-' . $randomClass;
}

//randomize array elements
shuffle($generatedRandomClassesArr);

highlight_string("<?php\n\$generatedRandomClassesArr =\n" . var_export($generatedRandomClassesArr, true) . ";\n?>");

echo '<br><br>';

highlight_string("<?php\n\$countValues =\n" . var_export(array_count_values($generatedRandomClassesArr), true) . ";\n?>");

?>

Check working demo

