gpt4 book ai didi

python - 在 Python 中随机化句子

转载 作者:行者123 更新时间:2023-12-04 08:15:51 25 4
gpt4 key购买 nike

我不久前完成了我的项目,该项目基于 YouTube 上的关键字对视频进行评论,它将使用随机库随机选择一条评论。
该程序在“随机化”评论以添加到
YouTube视频。我开始认为我可能需要提高随机性,事实是
它选择了第 4 条评论 (共 9 个) 7次 , 第 9 次 3 次 .这两个
结果接连发生,换句话说,它是连续发送相同的消息
当它意味着随机选择而不是重复时。
有什么办法可以增加随机性吗?如果你知道,请告诉我,我会很感激的!
PS:这更多的是阻止它在 YouTube 上重复相同的句子。
代码:

if __name__ == "__main__":
from googleapiclient.errors import HttpError
import random
import time
import sys

# Comments are getting loaded
comments = load_comments('Comments.txt')
# Getting the number of comments you want to add
number_of_comments = int(input('Enter the number of comments: '))
count, cycle, videoid_store = 0, 1, []
# Getting the keyword
keyword = input('Enter the Keyword: ')


# This loop keeps running until all comments have been added
youtube = authentication()
while count < number_of_comments:

print("Searching for videos .. (Cycle:%d)" %cycle)
time.sleep(10)

random.shuffle(comments)

最佳答案

尝试 random.choice()

x=random.choice(['option1','option2'])

关于python - 在 Python 中随机化句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65707313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com