Key generation in Digital Signature Algorithm
As the comments are quite spot-on, I shall just reproduce them and say that you should just follow the relevant standard which is FIPS 186-4 appendix A.1, which expands upon your intuition.


  The exact algorithm for generating the primes is specified in the DSS
  NIST FIPS 186-4 [(PDF)]  –
  Henrick Hellström


and


  One issue with the proposed algorithm is that the p generated will
  often be 3071- bit rather than 3072-bit, a stated requirement. Also,
  as pointed by Henrick Hellström, if you want DSA per the U.S.
  Department of Commerce's book, then appendix A.1 [(PDF)] is a
  must; also, following that procedure ensures the parameters are not
  cooked in some way; p and q essentially become
  nothing-up-my-sleeve. – fgrieu