算法1:
当数组个数=1000;生成时间约为16ms。
当数组个数=10000;生成时间约为203ms。
当数组个数=100000;生成时间无限。 因为The rand function returns a pseudorandom integer in the range 0 to RAND_MAX (32767). Use the srand function to seed the pseudorandom-number generator before calling rand.
那么也就是说:想要生成一个大于32767个元素数组的不重复随机数组则,不能使用算法1.
算法2:
random_shuffle()包含与<algorithm>
当数组个数=100000;生成时间约为15ms
当数组个数=1000000;生成时间约为203ms
当数组个数=10000000;生成时间约为2437ms = 2.4s
当数组个数=100000000(1亿);生成时间约为27687ms = 27.7s
可以看出,算法呈O(n)线性增加