#05AB1E, 44 5050 44 bytes
[õ0U.µ["BFSH"3ÝΩ©è«®ĀX+U¼®X3/+3@¾Xµ["BFSH"3ÝΩ©è«®ĀX+U¼X2›®+3@¾X-3›~#}Dθ'FÊI¾Q*#I¾Q#
Port of @xnor's Python 2 answer, so make sure to upvote him as well if you like this answer!
+6 bytes due to a bug-fix. Will probably edit again, and after that -6 bytes again thanks to @xnor has fixed his Python answer, since I have the feelingby porting his fix will beway more efficient fix in terms of bytes thancomparison to my current fix.temporary work-around, as I was expecting. ;)
Try it onlineTry it online or verify some more random outputsverify some more random outputs.
[ # Start an infinite loop:
õ # (Re)set the result-string to an empty string ""
0U # (Re)set variable `X` to 0
.µ # Reset the counter_variable to 0
[ # Start an inner infinite loop:
"BFSH" # Push string "BFSH"
3ÝΩ # Push a random integer in the range [0,3]
© # Store this random integer in variable `r` (without popping)
è # Index it into the string "BFSH"
« # Append it to the result-string
®Ā # If `r` is NOT 0:
X+U # Increase `X` by 1
¼ # Increase the counter_variable by 1
®X3/+X2›®+ # Calculate `X`/3`X`>2 (1 if truthy; 0 if falsey) + `r`
3@ # Check if this is larger than or equal to 3
¾X- # Calculate counter_variable - `X`
3› # Check if this is larger than 3
~ # If either of the two checks above is truhy:
# # Stop the inner infinite loop
} # After the inner infinite loop:
Dθ'FÊ '# Check if the string does NOT end with an "F"
I¾Q # Check ifIf the input and counter_variable are equal
* # If both checks above are truthy:
# # # Stop the outer infinite loop
# (and output the result-string at the top of the stack implicitly)