I'm trying to make a simple cache that stores values I've already generated so I don't append duplicate values into the text file. However, I've been having issues with this, no matter what I seem to try my program keeps appending duplicate values.
Here's my current code, if anyone could point me in the right direction it would be greatly appreciated:
import random
def test():
cache = open('cache.txt','a+')
for x in range(10):
number = random.randint(1,20)
if number not in cache:
cache.write(str(number) + '\n')
print("Finished.")
test()