Pseudo Random Number Generator
The statement bit_11 = '{0:b}'.format(T)[-11] actually extracts bit 10, because the convention is to number bits from zero, while indexing from the end of string starts at [-1].
Performing bit manipulations in string format is clunky. Use bitwise operators instead. For example, to extract bit 10: T &gt;&gt; 10 &amp; 1
Opening a file by a with statement ensures it will be closed. You can omit the close calls.
Strings have a zfill method that does the same as for i in range(16 - len(K)): K = '0' + K