Monte Carlo simulations of photohadronic processes in astrophysics