I tried to make a twitter bot to print random number but it print the same number while testing the command
import tweepy
import random
import time
import threading
import schedule
start = time.perf_counter()
while time.perf_counter() - start < 2:
random_number = random.randint(0,10000)
time.sleep(1.0)
def job():
print(random_number)
# run the function job() every 2 seconds
schedule.every(2).seconds.do(job)
while True:
schedule.run_pending()
What should I do in order to have random numbers?
Your first block defines the random_number
, which is then fixed.
You should compute the random number in your job
import random
import time
import threading
import schedule
def job():
print(random.randint(0,10000))
# run the function job() every 2 seconds
schedule.every(2).seconds.do(job)
while True:
schedule.run_pending()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.