在Python中,可以使用'random'模块中的'randint'函数生成随机整数,然后使用当前时间戳和随机整数生成唯一的随机数。具体实现如下:

import random
import time

def generate_unique_random():
    # 生成随机整数
    random_num = random.randint(1, 100000)
    # 获取当前时间戳
    timestamp = int(time.time() * 1000)
    # 将当前时间戳和随机整数拼接成字符串
    unique_str = str(timestamp) + str(random_num)
    # 返回字符串转化后的整数
    return int(unique_str)

调用'generate_unique_random'函数即可生成唯一随机数。


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

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