code for monte carlo class