import random

def random_elements(alist, writetofile = False, fname = 'output.txt'):
    # random.choice(alist)

    if writetofile:
        outfile = open(fname, 'w')
        
        for _ in range(4):
            outfile.write(str(random.choice(alist)) + '\n')
            
        outfile.close()
    else:
        for _ in range(4):
            print(str(random.choice(alist)))


mylist = [1,6,-3,9,10,20,55,2,12,15]
mylist2 = ['hello', 'goodbye', 'Skidmore', 'a', 'b', 'c']
random_elements(mylist)
random_elements(mylist2, True)
random_elements(mylist, True, 'randvals.txt')
