Is there any way to make data corruption intentionally in python3?
Question: I'm now making an application which basically corrupts the data. That's what
it does. However, I cannot find ways to save the corrupted data into a
variable. I want the corrupted data saved in a python list like "holder=[]" to
make them accessible later. Is there any way to do that?

    
    
    import random
    import time
    import threading
    
    
    def example():
        for counter in range(10):
            print(counter)
    
    
    def thread_set_1():
        thread1=threading.Thread(target=example)
        thread2=threading.Thread(target=example)
        thread3=threading.Thread(target=example)
        thread4=threading.Thread(target=example)
        thread5=threading.Thread(target=example)
        thread6=threading.Thread(target=example)
        thread7=threading.Thread(target=example)
        thread8=threading.Thread(target=example)
        thread1.start()
        thread2.start()
        thread3.start()
        thread4.start()
        thread5.start()
        thread6.start()
        thread7.start()
        thread8.start()
    
    def thread_set_2():
        thread1=threading.Thread(target=thread_set_1)
        thread2=threading.Thread(target=thread_set_1)
        thread3=threading.Thread(target=thread_set_1)
        thread4=threading.Thread(target=thread_set_1)
        thread5=threading.Thread(target=thread_set_1)
        thread6=threading.Thread(target=thread_set_1)
        thread7=threading.Thread(target=thread_set_1)
        thread8=threading.Thread(target=thread_set_1)
        thread1.start()
        thread2.start()
        thread3.start()
        thread4.start()
        thread5.start()
        thread6.start()
        thread7.start()
        thread8.start()
    


Answer: If I understand you correctly, you would like to save your output? I think
that this won't be possible using a simple array, as the global interpreter
lock is going to prevent simultaneous access by multiple threads to a global
variable. However, if you write your output to a file, this will work. If you
change your function `example` like so:

    
    
    def example():
        for counter in range(10):
            with open('testfile.txt','a') as fid:
                fid.write(str(counter))
    

and then run:

    
    
    open('testfile.txt','w') #create empty file
    thread_set_1()
    thread_set_2()
    

`testfile.txt` will contain seemingly random numbers. However, this is going
to be very slow, as the file is going to be opened and closed every time a
number is written.

The main reason to not use this procedure to create random numbers is that
they are not going to be truly random, as the numbers written to the file are
going to increase with time. You wrote that you plan on shuffling the numbers
afterwards; if you plan on using `random` for this (it is among your imports),
why do you want to additionally create your own random number generator?

