swapping the values of a vector , so that it has unique values.

Hello ,

I have a vector which stores positions .

CRectangle *_final_positions;// CRectangle is a simple rectangle(x,y,w,h)

// It has some values inserted in it .
for(int i = 0;i < 3;i++)
for(int j = 0;j < 3;j++)

_final_positions = NULL;
_final_positions = new CRectangle((float)j * 75,(float)i * 100,(float)75,(float)100);


//Finally , I want to swap these positions so I have written a function

for(int i = 0;i < _final_positions_List.size();i++)

int temp = GetRandomInteger(0,9);



Note :
where GetRandomInteger(min,max) generates a random integer starting from min to max.

** My problem is by doing this , I have some duplicate positions. How to solve this?

Hi, there is an stl function called random_shuffle which does what you want to do .
To use it, put
#include <algorithm>
in your header.

Topic archived. No new replies allowed.