Hi, you mention you were expecting your period the first week of August. Do you mean August 1 - 7 and no later than the 7th?
If your menstrual months are super regular, such as, always about 28 days long, sex on the 27th of July would be too late to produce a pregnancy if your period were expected on, say, August 4 or so. But if your months vary (sometimes 26 days from one period to the next, sometimes 32 days, etc.) there might be a chance that sex as late in July as the 27th would produce the pregnancy.
You mention having had sex in August with your boyfriend. Did you also have sex with your boyfriend earlier in July than the event on the 27th?
OK, let's try to figure it out. How did you get the due date of April 18?
Let's lay it out like this. You fill in the blanks.
First day of last period: July 23
Sex with random guy: July 27
Sex with boyfriend in July: unknown
Sex with boyfriend in August confirmed
Periods come at irregular intervals. Next period expected 'first week of August,' didn't arrive.
Discovered pregnancy on _________ (date)
by (__doctor's test) (__home test)
First ultrasound on ___________ (date)
Due date was given by doctor from (__first) (__later) ultrasound
(If the due date was from a later ultrasound, date of that ultrasound: _________)
This info should make it easier to answer whether the random guy could be the dad.
So, here's the data (please check it for accuracy), followed by some analysis.
Your last period began on July 23. You can't remember if you had sex with your boyfriend in July, but you did have one event with the other guy on July 27. You had sex throughout August with your boyfriend.
You didn't realize you were pregnant until November 21. You got your first estimated due date (it sounds like, from the doctor) of April 30, but not from an ultrasound.
Then on December 21, you got an ultrasound, and the doctor changed the due date to April 18. Because a due date of April 30 suggests conception around August 6-8, that seemed to rule out the random guy as the dad. But a due date of April 18 wouldn't (by itself) rule him out. Now you want to know if that change of due date means the random guy could be the dad.
Please feel free to clarify anything I got wrong, such as, if your period didn't begin on July 23 but instead ended on July 23.
Here's what I am thinking from what you described.
First thing to know is that your ultrasound was too late for precisely dating the pregnancy. Ultrasounds are pretty precise at it if done when you are very early in the pregnancy, like, the 7th week GA (which is the fifth week from conception), because embryos develop at a consistent rate in the first 7 weeks or so. But after that, some babies grow faster or slower than average. By your 12th week, if you were to ask a doctor to tell you when you conceived based on the ultrasound, a good doctor will give a margin for error to account for the variation in growth rate of babies. Most doctors would say "give or take a week" by the 12th week GA. By the time your 40th week of pregnancy rolls around, the margin for error (if using an ultrasound to try to determine a conception date) is +/- three weeks. In other words, they get less and less accurate for dating pregnancy the later in the pregnancy.
By the time you got your ultrasound on December 21, you were more than halfway through your pregnancy. A doctor would probably tell you there's a 1 1/2 to two-week margin for error if an ultrasound was used at that point to try to date conception.
I think that the better evidence for your boyfriend being the dad and not the random guy is that your period began on July 23. (I assume you didn't mean to say it ended on July 23, which would change this assesment.) A period beginning on July 23 tends to rule out having gotten pregnant on July 27, or even within a 5-day spread from July 27 (to account for the long time sperm can last in a woman's body). You would not be ovulating on July 27 or within 5 days of then either, unless you happened to know FOR SURE that your next period seriously would have come before August 6. (You said your cycles are irregular, not that your menstrual months are super short.)
So, the closeness in time between the sex with the random guy and your period tends to suggest Mr. Random is not the dad. The change of your due date based on the December 21 ultrasound doesn't affect this, since the ultrasound was too late to date conception with precision.
Did the random guy use a condom? Your odds would be even better if so.
In your shoes, I would get a DNA test when the baby is born just to be entirely sure and never wonder, and then forget it. You could either just tell your boyfriend the hospital requires one because you and he are not married, or if you weren't seeing him in July yet, you could explain that before you got together, you had one random sexual event, and though you are pretty sure it was too early to make any difference, you would like to do a DNA test when the baby is born just so there will never be any question. Another way to handle it if you don't want to tell him about the random event is to tell him that since he's a single guy, you assume he would be more comfortable if a DNA test were to be done so he would never wonder.
This is mostly to put your mind at rest, and in case something about the data above isn't correct and the random guy has a bigger chance than it sounds like. Once you do the DNA test that will be that.