python-函数

获取区间内不重复整数的无序列表

import random


def create_random_list(*tuple_num):
    """
        获取区间内不重复整数的无序列表
    :param tuple_num: int类型,一个参数为结束,0开始,两个参数,参数1开始,参数2结束。包前不包后
    :return: list列表 不重复整数的无序列表
    """
    list_number = []
    if len(tuple_num) == 1:
        if tuple_num[0] < 0:
            end = 1
            start = tuple_num[0] + 1
        else:
            start = 0
            end = tuple_num[0]
    else:
        start, end = tuple_num
    list_len = end - start
    while len(list_number) < list_len:
        number = random.randrange(start, end)
        if number in list_number:
            continue
        list_number.append(number)
    return list_number

 

posted @ 2022-12-08 13:58  跃动指尖  阅读(22)  评论(0)    收藏  举报