int nAttempts = 0;
while (nfound < nClusters && nAttempts <= 10)
{
// decide which indexes should be centers
IIntArray I = intsNew.arrayRandomIndexes(datasize, nsought);
ints.sort(I);
// get corresponding data points
IDataList datapoints = select(I);
// add new ones
for (int i=0; i<I.size(); i++)
{
if (isNew(acceptedCenters, datapoints.get(i)))
{
acceptedCenterIndexes.append(I.get(i));
acceptedCenters.add(datapoints.get(i));
}
}
nfound = acceptedCenters.size();