Created
July 13, 2022 15:52
-
-
Save 0x4248/c1363d424fc8022448d5405e9bccbeed to your computer and use it in GitHub Desktop.
A simulation to show how many videos someone watches on TikTok in one hour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
class Values: | |
video_types = [15,60,180] | |
hour = 3600 | |
def demo(): | |
input("This is a algorithm to show how many TikTok videos a person can consume (Press enter)") | |
print("Videos watches if all videos are 15s that are 100% watched:"+str(Values.hour/15)) | |
print("Videos watches if all videos are 60s (1m) that are 100% watched:"+str(Values.hour/60)) | |
print("Videos watches if all videos are 180s (3m) that are 100% watched:"+str(Values.hour/180)) | |
input("Now press enter to simulate someone (Press enter)") | |
time_left = Values.hour | |
videos_watched = 0 | |
while True: | |
current_video_time = random.choice(Values.video_types) | |
current_video_time = current_video_time - random.randint(0,current_video_time - 1) | |
time_left = time_left - current_video_time | |
if time_left <= 0: | |
print("Ran out of time") | |
break | |
videos_watched = videos_watched + 1 | |
print("Watched Video for "+str(current_video_time)+"s and i have "+str(time_left)+"s on Tiktok") | |
time.sleep(0.005) | |
print("I have watched "+str(videos_watched)+" in one hour") | |
def test(): | |
time_left = Values.hour | |
videos_watched = 0 | |
while True: | |
current_video_time = random.choice(Values.video_types) | |
current_video_time = current_video_time - random.randint(0,current_video_time - 1) | |
time_left = time_left - current_video_time | |
if time_left <= 0: | |
break | |
videos_watched = videos_watched + 1 | |
return videos_watched | |
def mass_test(tests): | |
total_videos_watched = [] | |
for i in range(tests): | |
time_left = Values.hour | |
videos_watched = 0 | |
while True: | |
current_video_time = random.choice(Values.video_types) | |
current_video_time = current_video_time - random.randint(0,current_video_time - 1) | |
time_left = time_left - current_video_time | |
if time_left <= 0: | |
break | |
videos_watched = videos_watched + 1 | |
total_videos_watched.append(videos_watched) | |
a = 0 | |
for i in total_videos_watched: | |
a = a + i | |
return round(a/len(total_videos_watched)),total_videos_watched | |
if __name__ == "__main__": | |
demo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment