Ayuda con el metodo Montecarlo modificado

Could you please turn this into a self-contained REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

Also, Homework inspired questions are welcome here, but you have to tell us what have you tried so far? what is your specific problem? We are more inclined towards helping you with specific coding problems rather than doing your work for you.

For guidelines about how to properly ask homework related questions here, please read our homework policy.

Nota: Por favor intenta hacer tus preguntas en inglés, ya que es el idioma preferido aquí y al usar español estás excluyendo a la mayoría de la conversación, reduciendo así tus posibilidades de obtener ayuda.