It is not clear what your goal is. You do not tell us. If you are trying to identify unique users, you are using two of the most unreliable data elements possible. Yes IP addresses are often used, but in conjunction with other data elements. Here is what you are missing.
IP addresses are often dynamic and can change with every session. As well IP addresses can be shared amongst many users. Also consider the limited number of web browsers and the user agents provided. It is extremely common that IP Address + User Agent will result in collisions as you suggest. It is extremely probable in fact. Also consider the amount of times that a user agent is bogus. It seems these days that user agents are bogus more times than they are accurate. Using the user agent for a pivotal data element is a horrible idea because of it's unreliability.
For some of my work, I use IP address and first access Epoch time but depending upon what you are trying to do, this may not be possible or practical. This works okay for a user id but there are far better methods. I do not use this method to track users per se.
If you are writing code, there are modules available to create a unique user id. This may be your best bet again depending upon what you are trying to do. I know that this feature is available in PHP if that is your language, though I cannot tell you what that would be since I do not use PHP. Perhaps someone can comment.