function [centroids, energy,centMap] = kClusters(k, data, boxExtreme,joePts,joEnergy)
centroids = zeros(k, size(data,2));
randMult = boxExtreme(2,1) - boxExtreme(1,1); 
randAdjust = boxExtreme(1,1); 
bestEnergy = realmax;

for j = 1:3
	%this picks k data points and puts them as centroids
	pickArray = 1:size(data,1);
	
	for i =  1:k
		num =0;
		while(num ==0)
			index = ceil(rand*( size(data,1) ) );
			num = pickArray(index);
			if( num ~= 0)
				pickArray(index)=0;
			end	
		end
		centroids(i,:) = data(num,:);
		save beforeIt centroids
	end

	% 	for i=1:k
	% 		centroids(i,:) = randMult .* rand(1, size( boxExtreme,2 ) ) + randAdjust;
	% 	end
	
	[centroids, energy,dataMap] = kIt(k,centroids,data,boxExtreme);
	centroids2 = centroids;
	save afterIt centroids2 
	if(energy < bestEnergy)
		bestEnergy = energy;
		bestConfig = centroids;
		centMap=dataMap;
	end
end

%if(joEnergy < bestEnergy)
if(joEnergy ~= realmax)
	
	for(i=1:3)
		newJoePts =zeros(size(joePts)+1,size(boxExtreme,2));
		for(i=1:size(joePts))
			newJoePts(i,:) = joePts(i,:);
		end
		newJoePts(size(joePts,1)+1,:) = randMult .* rand(1, size( boxExtreme,2 ) ) + randAdjust;
		[centroids, energy,dataMap] = kIt(k,newJoePts,data, boxExtreme);
		if(energy<bestEnergy)
			bestEnergy = energy;
			bestConfig =centroids;
			centMap=dataMap;
		end
	end
end

energy = bestEnergy;
centroids = bestConfig;
