Skip to content

Commit e9809f0

Browse files
committed
add function rand_list()
1 parent ed19784 commit e9809f0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

util/utils.py

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33
# Created by imoyao at 2019/5/14 14:16
44
import time
5+
import random
56

67

78
def show_time(func):
@@ -21,6 +22,19 @@ def foo(n):
2122
pass
2223

2324

25+
def rand_list(n=10):
26+
"""
27+
生成长度为 n 的 1000 以内随机数组
28+
:param n:int,希望生成的数组长度
29+
:return: 随机生成的乱序数组
30+
"""
31+
random_list = []
32+
for i in range(n):
33+
num = random.randint(1, 1000)
34+
random_list.append(num)
35+
return random_list
36+
37+
2438
if __name__ == '__main__':
2539

2640
foo(100)

0 commit comments

Comments
 (0)