In reply to Bharat100: Move a_i.randomize(); in front of the foreach loop. Also, there is no need to shuffle() the array.