Generate a Baseball Pitch String
Python 2, 128 bytes



from random import*
def g(n):
 x=i=S=0;r=''
 while(S&gt;2)+x&lt;3&gt;=i-S:x=randint(0,3);r+='BFSH'[x];S+=x&gt;0;i+=1
 return(i==n)*r or g(n)


Try it online!

Randomly generate the pitch string until the batter is done, output it if it turns out the right length, and otherwise try again from scratch.



Python 2, 136 bytes



from random import*
def g(n):
 B=H=F=S=0;r=''
 while(F+S&lt;3or'S'&gt;x)&gt;B/4+H:x=choice('BHFS');r+=x;exec x+"+=1"
 return(len(r)==n)*r or g(n)


Try it online!