Generate random LTL Formulae An LTL Formula l is defined by the following grammar (where &lt;x&gt; describes the non-terminal symbol x):

&lt;l&gt; ::= &lt;b&gt; | F &lt;l&gt; | G &lt;l&gt; | X &lt;l&gt; | (&lt;l&gt; U &lt;l&gt;) | (&lt;l&gt; W &lt;l&gt;) | (&lt;l&gt; R &lt;l&gt;) 
            | (&lt;l&gt; &amp; &lt;l&gt;) | (&lt;l&gt; \| &lt;l&gt;) | !&lt;l&gt;
&lt;b&gt; ::= BVar | True | False | (&lt;i&gt; &lt; &lt;i&gt;) | (&lt;i&gt; &lt;= &lt;i&gt;) | (&lt;i&gt; &gt; &lt;i&gt;) | (&lt;i&gt; &gt;= &lt;i&gt;) 
             | (&lt;i&gt; = &lt;i&gt;) | (&lt;i&gt; != &lt;i&gt;)
&lt;i&gt; ::= IVar | -128 | -127 | ... | 127 | (&lt;i&gt; + &lt;i&gt;) | (&lt;i&gt; - &lt;i&gt;) 
             | (&lt;i&gt; * &lt;i&gt;) | (&lt;i&gt; / &lt;i&gt;)


(I escaped a pipe to denote boolean or. You should not print that backslash in your output)

BVar and IVar represent variables of boolean and integral types respectively. Each must be one of four possible single character variable names, and there may by no overlap between BVar and IVar. For instance, you may choose a,b,c,d for BVar and w,x,y,z for IVar 

Note that all binary operators must have parentheses around them and that no other parentheses are allowed.

Your task is to write a function that takes one input encoding the maximal nesting depth of an LTL formula and prints a random formula limited by that depth (but not necessarily exactly that depth). The distribution does not have to be uniformly random, but each possible formula has to have a non-zero chance of being generated.

You may use ≤, ≥, and ≠ instead of &lt;=, >=, and !=.

You may add or remove whitespace as you see fit. Even no whitespace at all is allowed.

Examples:

f(0) -&gt; True
f(0) -&gt; d
f(1) -&gt; (a&amp;b)
f(1) -&gt; Fd
f(1) -&gt; (x&lt;y)
f(3) -&gt; (G(x!=y)|Fb)
f(3) -&gt; (x&lt;(w+(y+z)))


Standard loopholes are forbidden.

This is code-golf, so the shortest code in bytes wins.
Perl 5, 251 bytes

249 bytes code + 2 for -pa.



$d=I;sub a{map"($d$_$d)",@_}@I=(w..z,-128..127,a qw{+ - * /});@L=(@B=(a..d,True,False,a qw{&lt; &lt;= &gt; &gt;= = !=}),B,FL,GL,XL,"!".($d=L),a qw{U W R &amp; |});$_=$L[rand@L];0while s/L|B|I/@{$&amp;}[rand@{$&amp;}]/e;$;=$_;s/[^()]//g;0while s/\)\(//g;$_=y/(//&gt;"@F"?redo:$


Try it online!