Trying to deal with an issue in my first string quartet, where performers are faced with a probabilistic decision… being that musicians are not computers, I’m looking at pre-calculating these probabilities, whilst trying to find a way to keep my score system indeterminate (more on that later). Some code I knocked up today to calculate probabilities for weighted edges in a graph network.
### Weighted outcome calculator for Network #1 (String Quartet #1)
# owmtxy, feb 2013 - python, v.2.7
# Input up to 5 probability percentages, and calculate a weighted outcome
import random
elapsed = 0
duration = 0 #int(input("Enter duration: "))
while(elapsed < 840): # While the elapsed time is < 14 minutes
print("nEnter probabilites, smallest first (0 for unused edges)...")
# Enter each (accumulative) probability weighting (%)
val1 = int(input("Weighting A: "))
val2 = val1 + int(input("Weighting B: "))
val3 = val2 + int(input("Weighting C: "))
val4 = val3 + int(input("Weighting D: "))
val5 = val4 + int(input("Weighting E: "))
def makeRandom():
randomVal = random.random() # Generate a random 'deciding' value
randomVal = round(randomVal*100) #Scale it to a %
return(int(randomVal))
randomX = makeRandom()
print(randomX)
# Compare the randomX value to the probability boundries:
if(randomX <= val1): print("Outcome A") elif (randomX > val1) and (randomX <= val2): print("Outcome B") elif (randomX > val2) and (randomX <= val3): print("Outcome C") elif (randomX > val3) and (randomX <= val4): print("Outcome D") elif (randomX > val4) and (randomX <= val5): print("Outcome E") # Add the duration of the selected edge to the elapsed time duration = int(input("Enter duration: ")) elapsed += duration print("Elapsed time: ", elapsed/60) # Repeat until we reach > 14 minutes