Sharing a Python script for generating an 8th strumming pattern

For you geeks out there, here’s a python script for generating an 8 strum succession with missing Down labeled - and missing Up labeled *.
It will ask you for how many strums you want to produce.

Example output:

import random

# Define the base pattern
base_pattern = 'DUDUDUDU'

# Ask the user for the number of strum patterns to generate
num_patterns = int(input("Enter the number of strum patterns to generate: "))

# Generate and print the specified number of random strum patterns
for _ in range(num_patterns):
    # Convert the base pattern to a list for manipulation
    pattern_list = list(base_pattern)
    
    # Randomly choose whether to remove 'D' or 'U' and replace with '-' or '*'
    for _ in range(random.randint(0, 7)):  # Randomly remove up to 7 strums
        index_to_remove = random.choice(range(len(pattern_list)))
        if pattern_list[index_to_remove] == 'D':
            pattern_list[index_to_remove] = '-'
        elif pattern_list[index_to_remove] == 'U':
            pattern_list[index_to_remove] = '*'
    
    # Join the modified pattern list
    modified_pattern = ''.join(pattern_list)
    
    # Check if the pattern is the same as the base pattern and skip it
    if modified_pattern != base_pattern:
        # Print the modified pattern with delimiters
        print(f"|{modified_pattern}|")
7 Likes

Thanks for sharing.
Note that + is often used to abbreviate ‘and’ when counting 8ths.

1 & 2 & 3 & 4 &

1 + 2 + 3 + 4 +

You may want to change that character for one less ambiguous.

2 Likes

This is fun. :+1:

When I get back home I need to reserve some time to test the 500 patterns I just generated :grin:
I’m glad it produces some duplicates :grin:

Thanks Daniel.

1 Like

Done! :wink:

:sunglasses: :grin: :guitar:

Yeah, I noticed the occasional dupes too. Not exactly “random” but it’s good enough for what I was trying to accomplish.

1 Like

Daniel, in your initial posting the “+” character still has to be exchanged in the code block itself…

Thanks!

1 Like

Interesting. I thought I’d changed that in the post yesterday. Hummm.

I fixed it in the code above.

For anyone who wants to change the script it’s easy enough. I used “-” and “*”, those two values can be anything that you want.
If anyone is using the script, then I assume that they understand how to run a Python (.py) script from a command line interface (CLI) in either Windows (CMD or Powershell) or in Linux (Terminal). Which means they need to copy the script, paste it into a text file, name it with a .py extension, save it somewhere in the system’s PATH or in a directory they can easily access, and then run Python in the CLI.

:point_up_2: :point_up_2: :point_up_2:
If you can do this, then you are savvy enough to change those text substitution variables prior to saving the script to a text file.

Examples - Change to “v” and “^”

# Randomly choose whether to remove 'D' or 'U' and replace with 'v' or '^' 
# or any two character values you want
    for _ in range(random.randint(0, 7)):  # Randomly remove up to 7 strums
        index_to_remove = random.choice(range(len(pattern_list)))
        if pattern_list[index_to_remove] == 'D':
            pattern_list[index_to_remove] = 'v'
        elif pattern_list[index_to_remove] == 'U':
            pattern_list[index_to_remove] = '^'

Or - change to the Thai characters “ณ” and “ฉ”

if pattern_list[index_to_remove] == 'D':
            pattern_list[index_to_remove] = 'ณ'
        elif pattern_list[index_to_remove] == 'U':
            pattern_list[index_to_remove] = 'ฉ'

This (and any other code I may publish) are scripts that I’m writing for myself and which I’m happy to share if anyone may find them useful. Feel free to modify them! :sunglasses:

1 Like

I Just wanted to say, I made my earlier comment just for completeness reasons and I of course had your script already modified locally.

Apart from that, I really like your idea behind the script and I find it is nice source for inspiration. Of course you have to test the patterns that you get as output and see which of those you really like. I anyways found some patterns I previously haven’t thought about. So thanks once again for sharing! :smiley:

1 Like

I added it to my strumming practice last night. I took the first 5 patterns generated and loaded them into Justin’s Strumming Machine. A couple of those patterns were challenging to say the least. Fun way to make a 7 minute strumming practice - 5 minutes of practice and a couple of minutes setting up the Strumming Machine. :guitar:
For now. At some point in the future I’m going to have to work on 5 strumming patterns that my “go to in a pinch” set of patterns. Old Faithful is already on that list!

1 Like

I love this.

Something you could do to make it even more interesting is to allow the user to input the number of notes in the rhythm, e.g. 8, 12 (i.e. quarter-note triplets), 16, or whatever they fancy.

Replace the 7 in the number of notes to remove with the n - 1 where n is the number of notes the user entered.

You’d also need to build the pattern based on the value of n, either before replacing notes or switch to string concatenation with a coin flip for each character to determine whether to include it as D/U or -/*.

Anyway, fun idea, thanks for sharing!

1 Like