Skip to content

Instantly share code, notes, and snippets.

@subtra3t
Created December 21, 2020 08:21
Show Gist options
  • Save subtra3t/a541bfdc6be3c19344ee3adc719c04c2 to your computer and use it in GitHub Desktop.
Save subtra3t/a541bfdc6be3c19344ee3adc719c04c2 to your computer and use it in GitHub Desktop.
Python Matrix generator
# 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