How does TLS generate the shared secret? From many readings, I got to know that TLS generates master shared secrets using pre-master keys and uses the DH algorithm to generate the shared secret/Master secret. 

What values during the hello messages act as

1. P - Prime number

2. G - Generator

3. Secret primes owned by each parties
?

Why does it need a client-server random number along with the pre-master secret to generate the master secret as DH requires only p, q and (a,b) are generated on each side?
Selection of the Diffie-Hellman parameters

If you are asking about the TLS cipher suites that use a Diffie-Hellman exchange (basically the ones containing "DH" or "DHE"), it depends on whether static or ephemeral Diffie-Hellman certificates are used.


The ephemeral cipher suites (DHE_DSS, DHE_RSA, DHE_anon and the various elliptic counterparts) transmit the generator, the prime modulus and the public value in the server and client key exchange messages.
The static cipher suites using Diffie-Hellman (DH_DSS, DH_RSA) use the (fixed) parameters embedded in the server certificate. If a client certificate is used, the parameters have to match the server's.


Not all cipher suites use a Diffie-Hellman exchange, though; in the (widely used) RSA_* cipher suites, the client sipmly selects a random premaster secret and encrypts it using the server's public RSA key.

Purpose of the client/server random values

The client and server randomness serves to avoid ever using the same emaster secret twice; for example, when a static Diffie-Hellman ciphersuite is used with a client certificate, the server's and the client's Y value don't change between sessions. This is done by securely hashing the premaster secret (which might or might not be equal for different sessions) and the client and server random values (which are required to be different for different sessions).

Reusing the master secret could allow replay attacks or cause the symmetric cipher to reveal information about the payload data.