从列表中或数组中随机抽取固定数量的元素组成新的数组或列表
1:python版本:python里面一行代码就能随机选择3个样本
>>> import random >>> mylist=list(range(1,10)) >>> mylist [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> newlist = random.sample(mylist, 3) #从mylist中随机获取3个元素 >>> newlist [4, 7, 2] >>> newlist = random.sample(mylist, 3) #从mylist中随机获取3个元素 >>> newlist [4, 3, 1] >>> newlist = random.sample(mylist, 3) #从mylist中随机获取3个元素 >>> newlist [5, 9, 3] >>>
2:jQuery版本
那么jQuery中怎么随机选出固定数组数组[1, 2, 3, 4, 5, 6, 7, 8, 9]中的三个元素,并构造成新数组的?



