ClearAll["Global`*"]; 

Tabla[exp_] :=
Module[{aux, v, e},
v=BooleanVariables[exp];
aux = Join[v, {exp}];
 aux = DeleteDuplicates[aux];
aux = Join[{aux},   BooleanTable[ aux, v] ];
aux =aux/.{True->"T", False->"F"};
 TraditionalForm[TableForm[Grid[ aux,Frame->All]]]
]

el ={p, q, r,  p∧q, p∨q, ¬p, ¬q, ¬r, p∧¬q, ¬p∧q, ¬p∧¬q, ¬p∨¬q, Implies[p, r], Equivalent[q, r]};
expre =True; 
rv ="??";
genExpresionLogica:=Module[{op, it}, 
it = RandomInteger[{1, 4}];
expre =True;
Do[
termino = RandomInteger[{2, Length[el]}];
op = RandomInteger[{1, 4}];
Which[
op==1, expre = expre ∧el[[termino]],
op==2, expre = expre ∨el[[termino]],
op==3, expre = Implies[ expre ,el[[termino]]],
op==4, expre = Equivalent[ expre ,el[[termino]]]
]
,{n, it}
];
If[Length[expre]==0, genExpresionLogica, expre]

]
 

expresion=genExpresionLogica;
 
Manipulate[
Dynamic@Button[ 
TraditionalForm[expresion]
, Appearance->"Frameless" ],
Dynamic@Button["Nuevo ejercicio",rv="";expresion=genExpresionLogica ], FrameLabel->Style["Haga la tabla de verdad para esta expresión"]
]
 Manipulate[Dynamic@Button[rv, "" ,  Appearance->"Frameless"],
Dynamic@Button["Ver respuesta", rv =Tabla[expresion]] 

]

Autores: Juan Félix Ávila Herrera y Enrique Vílchez Quesada, Escuela de Informática, Universidad Nacional de Costa Rica,  .