I can not understand why the following use of ifthenelse and pgf give me an error :
\documentclass{article}
\usepackage{pgf}
\begin{document}
\pgfmathrandominteger{\a}{2}{7}
\pgfmathrandominteger{\b}{2}{3}
\def\c{\pgfmathparse{ifthenelse(\a!=\b,\a,int(\a+1))} \pgfmathresult}
\def\M{ \pgfmathparse{int(\c)} \pgfmathresult}
$\M$
\end{document}
give me the error
! TeX capacity exceeded, sorry [input stack size=5000].
\@inmathwarn ...latex@warning {Command \protect #1 invalid in math mode}\fi
l.21 $\M
$
While the code
\documentclass{article}
\usepackage{pgf}
\begin{document}
\pgfmathrandominteger{\a}{2}{7}
\pgfmathrandominteger{\b}{2}{3}
\def\c{\pgfmathparse{ifthenelse(\a!=\b,\a,int(\a+1))} \pgfmathresult}
\pgfmathparse{int(\c)}
\def\M{\pgfmathresult}
$\M$
\end{document}
give me the error :
! Incomplete \iffalse; all text was ignored after line 20.
<inserted text>
\fi
<*> bugpgf
As long as i don't try to make a computation on \c there is no error; as for example in
\documentclass{article}
\usepackage{pgf}
\begin{document}
\pgfmathrandominteger{\a}{2}{7}
\pgfmathrandominteger{\b}{2}{3}
$\a$ $\b$ $\c$
\def\c{\pgfmathparse{ifthenelse(\a!=\b,\a,int(\a+1))} \pgfmathresult} \end{document}
Latex seems to tell me i missed the fi part of the command but I did not did I ? the use of
\a!=\b ?\a : int(\a+1)
has similar effects. Any help would be greatly appreciated.

\defand\pgfmathsetmacrowill overwrite existing macros without warning, and redefining them could potentially cause problems elsewhere.\a,\band\care all defined by default, see https://tex.stackexchange.com/questions/19111/short-names-for-macros – Torbjørn T. Feb 20 '18 at 20:40