首先定义随机数生成函数

import random

def generate_random(): A = random.randint(1, 7) B = random.choice([8,9,10,11,12,13,17]) C = random.choice([18,19,20,22,23,24,26]) D = random.randint(27, 33) E = random.randint(29, 35) X = random.randint(1, 7) Y = random.randint(6, 12) return [A, B, C, D, E, X, Y]

生成1.5亿个随机数组

n = 150000000 arr_list = [] for i in range(n): arr_list.append(generate_random())

计算重复和不重复数组个数

unique_arr = set(map(tuple, arr_list)) unique_count = len(unique_arr) repeat_count = n - unique_count

统计重复次数

count_dict = {} for arr in arr_list: arr_tuple = tuple(arr) if arr_tuple in count_dict: count_dict[arr_tuple] += 1 else: count_dict[arr_tuple] = 1

输出前十个重复次数最多的数组

most_common = sorted(count_dict.items(), key=lambda x: x[1], reverse=True)[:10] print("前十个重复次数最多的数组:") for arr, count in most_common: print(list(arr), count)

输出前十个重复次数最少的数组

least_common = sorted(count_dict.items(), key=lambda x: x[1])[:10] print("前十个重复次数最少的数组:") for arr, count in least_common: print(list(arr), count)

输出重复和不重复数组个数

print("重复数组个数:", repeat_count) print("不重复数组个数:", unique_count

获得一个7位随机数组ABCDEXY分为前5个数字ABCDE和后2个数字XY;其中A在1到7这7个数字中随机B在891011121317这7个数字中随机C在18192022232426这7个数字中随机D在27到33这7个数字中随机E在29到35这7个数字中随机X在1到7这7个数字中随机Y在6到12这7个数字中随机;前5个数字ABCDE从小到大排列互不相同后2个数字XY从小大到达排列互不相同;将得到的

原文地址: https://www.cveoy.top/t/topic/eH5P 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录