/// <summary>
/// get different random
/// </summary>
/// <param name="arrNum"></param>
/// <param name="tmp"></param>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <param name="ra"></param>
/// <returns></returns>
public int[] getNum(int count, int total)
{
int[] index = new int[total];
for (int i = 0; i < total; i++)
{
index[i] = i;
}
Random r = new Random();
//用来保存随机生成的不重复的count个数
int[] result = new int[count];
//int site = total;//设置下限
int id;
for (int j = 0; j < count; j++)
{
id = r.Next(0, total - 1);
//在随机位置取出一个数,保存到结果数组
result[j] = index[id];
//最后一个数复制到当前位置
index[id] = index[total - 1];
//位置的下限减少一
total--;
}
return result;
}
判断新旧质心是否相等
/// <summary>
/// judge the value of center
/// </summary>
/// <param name="center"></param>
/// <param name="newcenter"></param>
/// <param name="ok"></param>
/// <returns></returns>
private static bool judge(double[] center, double[] newcenter, bool ok)
{
int count = 0;
for (int i = 0; i < newcenter.Length; i++)
{
if (center[i] == newcenter[i])
{ count++; }
}
if (count == newcenter.Length)
{
ok = true;
}
return ok;
}