生成一个随机数序列,并可以设置范围及数量


import random


class RandomGen(object):

    def __init__(self, start=1, stop=1000, total=10):
        self.__start = start
        self.__stop = stop
        self.__total = total

    def gen(self):
        result = [random.randint(self.__start, self.__stop) for _ in range(self.__total)]
        return result


result = RandomGen(20, 100, 5)
print(result.gen())


文档更新时间: 2021-02-01 22:56   作者:闻骏