Recently I learned that the cardinality of a minimal set of generators of a finite $p$-group $G$ is well defined namely it is equal to the dimension of $H^1(G,\mathbb{F}_p)$. Moreover, if $S:=\{g_1,\ldots,g_s\}$ is a minimal generating set of $G$ then the cardinality of a minimal set of relations with respect to $S$ is also a well defined integer, namely it is equal to the dimension of $H^2(G,\mathbb{F}_p)$.
For a general group, the cardinality of a minimal set of generators is not well defined. Take for example the symmetric group of degree $n$. For instance you may get a cardinality equal to $2$ or $n-1$.
Q1: So for what class of finite groups do we expect the cardinality of a minimal generating set to be well defined?
P.S. By "a minimal set of generators" I mean "irredundant", that is the set that generates the group, but no proper subset does.