Skip to content

Instantly share code, notes, and snippets.

@hcgatewood
Last active July 25, 2024 23:33
Show Gist options
  • Save hcgatewood/e1f42b371ab56037eeda to your computer and use it in GitHub Desktop.
Save hcgatewood/e1f42b371ab56037eeda to your computer and use it in GitHub Desktop.
Print a random note at the passed interval, defaulting to every 4 seconds
#!/usr/bin/env python3
"""
random_note.py prints a random musical note at the passed interval (seconds).
If no interval passed, defaults 4 seconds.
"""
import itertools
import random
import time
import sys
notes = "A B C D E F G".split()
acc_symbs = ["", "♯", "♭"]
combinations = ["".join(el) for el in itertools.product(notes, acc_symbs)]
try:
interval = int(sys.argv[1])
except:
interval = 4
while True:
time.sleep(interval)
print(random.choice(combinations))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment