forked from Junbo2002/wjx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfun.py
58 lines (47 loc) · 2.3 KB
/
fun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import random
provinces = {
'吉林省': [125.326800, 43.896160], '黑龙江省': [126.662850, 45.742080],
'辽宁省': [123.429250, 41.835710], '内蒙古自治区': [111.765220, 40.817330],
'新疆维吾尔自治区': [87.627100, 43.793430], '青海省': [101.780110, 36.620870],
'北京市': [116.407170, 39.904690], '天津市': [117.199370, 39.085100],
'上海市': [121.473700, 31.230370], '重庆市': [106.550730, 29.564710],
'河北省': [114.469790, 38.035990], '河南省': [113.753220, 34.765710],
'陕西省': [108.954240, 34.264860], '江苏省': [118.762950, 32.060710],
'山东省': [117.020760, 36.668260], '山西省': [112.562720, 37.873430],
'甘肃省': [103.826340, 36.059420], '宁夏回族自治区': [106.258670, 38.471170],
'四川省': [104.075720, 30.650890], '西藏自治区': [91.117480, 29.647250],
'安徽省': [117.285650, 31.861570], '浙江省': [120.153600, 30.265550],
'湖北省': [114.342340, 30.545390], '湖南省': [112.983400, 28.112660],
'福建省': [119.296590, 26.099820], '江西省': [115.910040, 28.674170],
'贵州省': [106.707220, 26.598200], '云南省': [102.709730, 25.045300],
'广东省': [113.266270, 23.131710], '广西壮族自治区': [108.327540, 22.815210],
'香港': [114.165460, 22.275340], '澳门': [113.549130, 22.198750],
'海南省': [110.348630, 20.019970], '台湾省': [121.520076, 25.030724],
}
def random_option(num: int):
x = random.randint(1, num)
# print(x)
return x
def random_multi_select(num: int):
# 多选的数量
length = random_option(num)
pre = []
# 顺序排序
for i in range(1, num+1):
pre.append(i)
# 洗牌算法
index = num - 1 # 从数组的最后一个数(下标为i)开始
while index > 0:
index_2 = random.randint(0, index)
# 将得到的下标对应的元素和最后一个数交换
pre[index], pre[index_2] = pre[index_2], pre[index]
# 将最后一个数拿出数组
index -= 1
return pre[0:length]
def random_position():
index = random.randint(0, len(provinces)-1)
return list(provinces.values())[index]
if __name__ == '__main__':
# res = random_multi_select(5)
# print(res)
random_position()