Let $G$ be a finite group and let $w$ be a word in $k$ variables. We write $P_w(g)$ the probability that a random tuple $(g_1,\ldots,g_k)\in G^{(k)}$ satisfies $w(g_1,\ldots,g_k)=g$. For non-solvable groups, it is shown by Abért that $P_w(1)$ can take arbitrarily small values as $n\rightarrow\infty$. Nikolov and Segal prove that for any finite group, $G$ is solvable if and only if $P_w(1)$ is positively bounded from below as $w$ ranges over all words. And $G$ is nilpotent if and only if $P_w(g)$ is positively bounded from below as $w$ ranges over all words that represent $g$. Alon Amit conjectured that in the specific case of finite nilpotent groups and for any word, $P_w(1)\ge 1/|G|$.

We can also consider $N_w(g)=|G|^k\cdot P_w(g)$, the number of solutions of $w=g$ in $G^{(k)}$. Note that $N_w$ is a class function. We prove that if $G$ is a finite $p$-group of nilpotency class 2, then $N_w$ is a generalized character. What is more, if $p$ is odd, then $N_w$ is a character and for $2$-groups we can characterize when $N_{x^{2r}}$ is a character. What is more, we prove the conjecture of A. Amit for finite groups of nilpotency class 2. This result was indepently proved by M. Levy. Additionally, we prove that for any word $w$ and any finite $p$-group of class two and exponent $p$, $P_w(g)\ge 1/|G|$ for $g\in G_w$. As far as we know, A. Amit's conjecture is still open for higher nilpotency class groups. For $p$-groups of higher nilpotency class, we find examples of words $w$ for which $N_w$ is no longer a generalized character. What is more, we find examples of non-rational words; i.e there exist finite $p$-groups $G$ and words $w$ for which $g\in G_w$ but $g^{i}\not\in G_w$ for some $(i,p)=1$.