That is an excellent question and one that is best answered by your primary care doctor
or a doctor specializing in the urogenital system such as a urologist
. Blood in semen can be from a variety of causes including trauma to the penis/scrotum, rough sexual intercourse or masturbating multiple times. Based upon your history, it would seem that perhaps the multiple masturbations caused you to have blood in the semen and this was the reason that you noticed blood in the semen and urine. This may also explain why you had pain in your penis as this can definitely be a cause of this. Less likely causes for blood in semen and urine include infections and tumors but because there is a risk of something serious being the cause of your bleeding
, it is important that you see a doctor about this who can decide the appropriate work up and treatment options available for you. They may want to perform further testing such as a scope or they may observe you to see if this resolves and counsel you on vigorous masturbation and sexual intercourse. If you notice excessive or worsening blood coming from your penis, then you should see a doctor on an urgent basis.