How can I create a random group of order $4096$ with a center of size $2$ ?
The algorithm should be able to create every possible group with the given properties in principle. I think the list of groups with the required properties is far too large and probably not even known.
I tried semidirect products. But first, I can produce only a small part of the possible groups with that and second, either there are too many homomorphisms (and I do not know whether GAP can choose a random homomorphism) or the groups I get have a center with a size larger than $2$.
I did not find a command in GAP constructing a random group of a given order, if the list of all groups is not available.
Any suggestions ?
This might be a way to achieve the desired goal, but I do not claim that it is the best way. (Whatever "best" might mean)
First, some work. Higman counted the number of $p$-class 2 groups (length of the lower exponent-$p$ series is 2) of order $p^n$ and concluded that there are at least $p^{2(n^3-6n^2)/27}$ such groups. Therefore, there are at least $2^{64}$ groups of order $4096$.
If you want a $2$-group with center of order $2$, then the $p$-class of the group can range from 3 to 12. If the $p$-class is 2, then the Frattini subgroup is a central subgroup, and in this case is equal to the center. Therefore, $G$ is $11$-generated and $G'=Z(G)=\Phi(G)$, so $G$ is extraspecial which cannot be true. Alternatively, the commutator map is a symplectic form of an odd dimensional space, and therefore, has a radical. Hence, the center has more than 2 elements.
If the $p$-class is $c\in\{3,...,12\}$, then $G$ is a central quotient of the $p$-covering group of $G/P_c(G)$. Specifically, if $P$ is the $p$-covering group of $G/P_c(G)$, then for some $H<Z(P)$, with $[Z(P):H]=2$, $G\cong P/H$. (Details: https://en.wikipedia.org/wiki/P-group_generation_algorithm)
The next issue one might consider is distribution. It seems that the larger the $p$-class, the fewer the number of groups bounded by a specific order. I don't think a statement like this has been proven, but there is data to back this is belief. Therefore, it seems most groups with a center of order 2 would be $p$-class 3. Hence, applying a uniform distribution to $p$-class would not result in a uniform distribution among the groups of order $4096$ and center of order $2$. I'm not sure if you care about this, but it's worth a mention.
With these ideas, one way to generate a random group would be the following (this is basically the $p$-group generation algorithm).
It is possible that at some point in this, the group is terminal. That is, it is equal to its $p$-cover. If this happens, start over or backtrack.
To construct a random group of $p$-class 2, it is enough to construct $d_2$ random $d_1\times d_1$ matrices along with a quadratic map from a $d_1$ dimensional vector space into a $d_2$ dimensional vector space. I'm not sure if GAP has commands to do this, but if $d_1+d_2\leq 9$, then you can choose a random $p$-class 2 group from the databases in GAP and go from there.