Awesome, thanks for bringing the progress bar to my attention, I didn't know I could put that in there.
So I added a progress bar and it turns out the code wasn't getting hung up it was just taking a really long time. What was confusing me was that the time it was taking to complete was increasing exponentially while I was increasing the iterations linearly. 1000 iterations would take about 1 sec, 5000 would take like 20 secs, 10000 would take around 2 min, etc.
The code was just appending a single point to a curve with each iteration, each point would have a new random angle/distance from the last. I guessed that using the curve command in every iteration was what was slowing it down, so I changed it so that each iteration just calculates the new point location and adds it to a list. Once all iterations are completed, use the list to append all the new points at once.
cmds.curve(seg.name, ws=True, a=True, p=newPoints)
This dramatically improved things. I can run 50000 iterations in just a few secs. However there does seem to be a limit to how many points can be appended with this single command. I tried running 100000 and the progress bar fills up in just a few secs but it seems to get hung up trying to execute the curve command at the end. Not that I need to do that many but I am curious why it gets stuck. Anyway here's what is being iterated:
while pointCount < totalPoints:
if random.random() < 0.5:
growth = random.uniform(0.1,0.2)
else:
growth = random.uniform(0.9,1.0)
pAng = random.uniform(pAng - 0.78, pAng + 0.78)
aAng = random.uniform(-1.57,1.57)
seg.gPoint = (gPoint[0] + growth*math.sin(aAng)*math.cos(pAng),
gPoint[1] + growth*math.cos(aAng),
gPoint[2] + growth*math.sin(aAng)*math.sin(pAng))
newPoints.append(gPoint)
cmds.progressBar(progressControl, edit = True, step = 1)
pointCount += 1
cmds.curve(name, ws=True, a=True, p=newPoints)
cmds.deleteUI( wind )