dimanche 16 avril 2017

How to make random algorithm more efficient

I wrote a piece of code that simulate the binary numbers flow in the Matrix. It works perfectly fine, and whenever I run this code people ask if I am hacking something.

import random
import time

while True:
    for j in range(204): #my full screen terminal is 204 characters wide
        print(random.randint(0,1),end='')
        time.sleep(0.0001)
    print('')

However, this code is very inefficient and drains lots of battery. So is there anyway to make this code more power efficient? Also, I don't want to have a huge amount of I/O to my hard drive.




Aucun commentaire:

Enregistrer un commentaire