Random Number Problem
时间:2006-10-10 来源:bbflyerwww
# coding: cp936
"""
Random Number Problem
生成一个随机个数(1<n<=100)的随机数(0<=v<=2^31-1)清单.然后随机选取一些随机数
(1<m<=n).对它们进行排序,再把这个随机子集显示出来.
@author 寒江风
@date 2006-10-9
""" import random def main():
# 生成n个随机数个数 1 < n <= 100
n = random.randint(2, 100)
print '总随机数:%d' % (n)
# 生成n个随机数
k = int(2**31-1)
li = []
for i in range(n):
v = random.randint(0, k)
li.append(v)
# 从n个随机数中随机选m个 1 < m <= n
m = random.randint(2, n)
print '选取%d个随机数从总%d个随机数中' % (m, n)
subli = random.sample(li, m)
# 对m个随机选取的数排序
subli.sort()
print subli if __name__ == '__main__':
main()
Random Number Problem
生成一个随机个数(1<n<=100)的随机数(0<=v<=2^31-1)清单.然后随机选取一些随机数
(1<m<=n).对它们进行排序,再把这个随机子集显示出来.
@author 寒江风
@date 2006-10-9
""" import random def main():
# 生成n个随机数个数 1 < n <= 100
n = random.randint(2, 100)
print '总随机数:%d' % (n)
# 生成n个随机数
k = int(2**31-1)
li = []
for i in range(n):
v = random.randint(0, k)
li.append(v)
# 从n个随机数中随机选m个 1 < m <= n
m = random.randint(2, n)
print '选取%d个随机数从总%d个随机数中' % (m, n)
subli = random.sample(li, m)
# 对m个随机选取的数排序
subli.sort()
print subli if __name__ == '__main__':
main()
相关阅读 更多 +