impl generate_k function in kmeans