Getting distinct enum values C++
<p>I'm trying to get a distinct value from my enumeration using void pointers.</p>

<p>I've an enum declaration of a list of animals</p>

<pre><code>enum Animal {Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Sheep, Monkey, Rooster, Dog, Pig};
</code></pre>

<p>So firstly, i have a function that returns me a value from my enumeration randomly</p>

<pre><code>VoidPtr getAnAnimal()
{
   VoidPtr anAnimal;

   Animal *a = new Animal;

   int k = rand() % 12;

   *a = static_cast&lt;Animal&gt;(k);

   anAnimal = a;

   return anAnimal;
}
</code></pre>

<p>Then during my construction of array, I've a conditional statement that states if the array has the same value, it is suppose to randomly generate another enum value</p>

<pre><code>void constructSet(VoidPtr* animalArray, int size)
 { 

   for(int i = 0; i &lt; size; i++)
   {
       animalArray[i] = getAnAnimal();

        int k = 0; 

       while ((k &lt; i) &amp;&amp; (animalArray[i] == animalArray[k]))
       {     
           animalArray[i] = getAnAnimal();   

           k++;
       }        
   }

}
</code></pre>

<p>Unfortunately, it still returns me the same enum value despite calling for another value if the array are the same. </p>