Created
December 21, 2020 08:21
-
-
Save subtra3t/a541bfdc6be3c19344ee3adc719c04c2 to your computer and use it in GitHub Desktop.
Python Matrix generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This uses Python generators, so you can keep it open 24/7 and it won't crash your device or occupy a single byte of memory! | |
def matrix(): | |
""" | |
Pass to this function a single iterative argument (preferably a tuple) that contains the characters or words | |
that you want the matrix to randomly take values from | |
""" | |
from random import randint | |
char = val_set[randint(0, len(val_set) - 1)] | |
while True: | |
yield char | |
char = val_set[randint(0, len(val_set) - 1)] | |
# To use this, iterate over this function's return value, and print it with end parameter's value set to an empty string | |
# Like this: | |
""" | |
val_set = (0, 1) | |
for c in matrix(): | |
print(c, end="") | |
""" | |
# To end the program, or use a different value set, execute ^C or CTRL + C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment