 So, hopefully this Monte Carlo simulation is just racking your brain and you're trying to figure out what you need to do if you're kind of reading. We have a purse that's going to include a quarter, a quarter, a quarter, a penny, a penny, a penny. Given these six coins, if I draw three coins out, meaning I remove three of these letters from my list, what's the probability that I'm going to have all three of the same coin type? So, all quarters are all pennies. Well, if we think about this for a second, let's just kind of look at what we're doing here and let's think about drawing one. So, draw one. Well, let's randomly, well, even before we get to that, let's think about this because we're dealing with our probability and this is probably going to be a little good indicator for when we start to do our Monte Carlo simulation. So let's say, for example, pennies. What is the probability of drawing a single penny from our purse right now? Well, if we look at it, we count this up, we see that we have one, two, three pennies. So we have three potential pennies across four, five, six. Across six potential outcomes, we can reduce this down into one half. All right, so we've now drawn out a single penny. What are we left with? Well, in here, we're now left with a quarter, a quarter, a quarter, a penny, a penny. One of our pennies is gone. Now, what happens with drawing two? Draw two. Now, what is our probability? Again, we go, I have one penny, two pennies, over three, four, five coins. Okay, well, I've drawn out my next penny in theory and then we're saying draw number three. I only draw three pennies total. So this time, what's our probability? Well, we have one penny and we have two, three, four coins. So as you can see, our probability slowly starts to diminish as we keep on drawing pennies. Now if we kind of take these numbers and we multiply them together, that's actually going to be beneficial to us. That's going to tell us our overall probability of drawing penny, penny, penny. One half times two times one, that's going to equal two. Two times five times four, two times five is 10 times four. That's going to give me 40 and if I reduce it down, I can get one over 20. Now, that's just for if I draw three pennies. What happens if I draw three quarters? Again, that's part of the question. Well, the same thing. It's the same mathematics that go in here, but instead of it now just being 120, since I'm looking at both quarters or pennies, both of these come in. I can add these together and now my color is going to be two over 20 or one tenth. When you're presenting this out into your code, you should see the probability of drawing three coins of the same type, dash zero point 10, zero, zero. This part right here will fluctuate, but it should stick around the one tenth range. Let's actually take a look at this and see if we can't get a little bit of some insight on where to begin. That's a really sucky part is I gave you nothing and I expect everything. If we think about it, one of the things that we did was we already did this. If we think about the Pascal formula, when we checked to see if we had two sixes when we dice rolled, what was it that we did? The first thing we did was we stored a yes. How many times did this happen? Did I get it this time? Yes. All right. Well, that's going to get incremented. No. Well, I don't. I only keep track of the number of times it gets incremented. One of the things we've talked about in the past is making constants. I'm going to actually use that same kind of structure I did here inside of our little simulation where I say q and p and I'm going to do that in here. I'm going to say final int p equals one, final int q equals two. Now one and two, those are arbitrary numbers. I could have made them 500 and three. I chose one and two just because they're going to be good easy numbers for us to kind of distinguish from. These are ones, quarters are twos. Now when I design up my purse, again, I'm making an array. If we look at, again, our drawing, let me clean this up for a second, let me boom. If we look at what we had in here, we had, again, a quarter, quarter, quarter, penny, penny, penny. This looks like a collection of data. A collection of data is an array. I'm just going to come in here and now say quarter, quarter, quarter, penny, penny, penny. That made a really nice thing because now, again, I have a simple array that's going to store my coins. Again, because I'm making my coins integers, I can just use an integer array. Now we get into at least a little bit more of the complex part of it. How do I determine which one to draw? We've already learned how to generate random numbers in our class so far, so this isn't too far off. If you're curious, maybe you know this already, I want to generate a random number based on the size of my purse because what happens if I add another coin in there? I add a nickel. My index is going to be equal to int math dot random times purse dot length. There we go. Now, again, what this is going to do, this is going to generate for me now a randomized index from zero to five because we don't include six. Remember, math dot random only works from 0.0 to 1.0, not including 1.0. We keep on going. Now that I have this index, I'm going to actually create another array. I'm going to create an array called int drawn coins. I said make it an array. How many coins did we say we wanted to draw? We want to draw three coins. Now I'm going ahead and I'm just setting that equal to a blank array right now, new int three. Now why? Because, again, that's going to say I have my coins or I have these slots readily available for me to now draw coins from. From here, I can go ahead and start to expand on this a little further. Now, I can do my first coin. I can go drawn coin zero equals purse at index. That's going to now take whatever index is randomly generated. Let's just assume it's two. It's going to take the queue from here and put it here. Now, here's the part that kind of confuses some of you. How do I remove it from my array? Arrays are immutable. Remember that means I can't just magically change their size. What do I have to do? What I can do is I can create a new array that's going to be one size smaller and I just copy all of my elements over. When I run into the index that I've already found as my remove, I just don't add that one to my array. In our case, what we would do here is I would simply say four. Actually, I need to create my new purse. Int new purse equals new int purse.length minus one. Again, I've removed a coin from my purse. Instead of having six elements, I'm only going to have five elements. Now that I have my five elements, that gets shrunk down. I expand on this further. Like I said, I'm going to go through every single element in my purse array and copy it, except for the index, except for the one that was randomly generated to be removed from my list. To do this, for int i equals zero, i is less than purse.length i plus plus. This is going to allow me to go through every element of my purse array and I want to, again, take that and store it into new purse. New purse at i equals purse at i. Now this is not going to work. Again, because if I ran this right now, it would error. Why? Because new purse is smaller. What do I do? Well, the first thing I have to do is I have to check if i equal equal index. If it does, if i equals equals index, then I need to actually change this. I need to say, instead of this one, we need to continue. Well, continue tells me that, again, that's going to move forward. It's going to ignore the rest of this code and just move to the next iteration of my loop. Now, i, we're still kind of running into an issue because i is going to generate a random, or it's going to generate a number from zero to five. Five is a big deal because new purse can only have indexes zero, one, two, three, four. I actually have to create another integer right before my for loop. I'm just going to call it j and j is what's going to be what I work with over here in new purse and j is going to get incremented because I need to keep track of how many times I've added an element into new purse. I continue to go through this process. This right here, let's just see how this kind of works in one instance. I run my debugger. I run my debugger. The processing, here we go, all right. Here we are. Let me resize this good. I step into my simulation. Yes. Yes, gets turned into a zero, zero because I've never run it and I haven't checked it yet. P, I'm making my pennies. Q, I'm making my quarters. I'm making my array of pennies and quarters. I'm now saying generate a random number, so five. That's dealing with this guy right here. That's last one. Now, drawn coins. Draw coins has no numbers to them, zeros. Those are none of the coins that I've laid out in my purse. I keep on going. Now, drawn coins, notice I've put my penny into drawn coins and I need to now make a new purse so that I can copy these things over. Again, notice purse has zero, one, two, three, four, five elements, so six total. New purse, zero, one, two, three, four. It only has five total. I'm going to start going through these. I make a J so that I can keep track of where I am in new purse and I'm now going to make an I that keeps track of where I am inside of my normal, my old purse. All I'm going to do is I'm going to go through and if I equals index, I equals index. Right now you see that's zero and five. They don't equal each other, so I don't deal with it. Every the element at purse I, at purse zero, which is two, into new purse at zero. You can see it changes it to a two. I go through this a few more times and you see every element is going to get added. Now, when I get to five, I equals five, index equals five. If I equal, equal index, if five equals five, notice it says continue. It does that instead. Moving on. Now we have it saying return, but what I've just done is I've now copied over into a new purse. What I want to do with this is I need to expand on this. I need to turn this into a three attempt because, again, I'm drawing three coins, not just one three. I take all of this code right here and I put it into a for loop, int I equals zero. I, well, I'm not going to say I because I have an I somewhere else. And draw, as long as draw is less than three, because that's how many times we're drawing, draw plus plus, and all I did was I copy and pasted that information in. Instead of doing draw coins at zero, I changed it to draw on coins at draw. Now what happens is I'm going to go through my song and dance multiple times. Let's run through our debugger one more time. I run through the song and dance, draw on coins, notice I've already said it once. I'm copying over my purse right now. There's actually something we forgot to do, and I'll show you in just a second. Purse never changes. Purse still has five elements in it. The last thing we have to do right before we finish is we have to come in here and we have to say purse equals new purse. This is actually why we were making the new purse the entire time is because eventually we were looking to have it replace the old purse. So now let's take a look at it again. I'm going to keep track of purses this time as I go through it. Purse doesn't look like it changes much. Pretty neat so far, but look what just happened there. Notice purses now instead of it being six elements long, it is five elements long. If I go through the song and dance again, it shrunk again. It's now four elements long, and then it will run through it the entire time. The last little thing I'll give you guys before I stop doing everything for you is now all I need to do after I've drawn my coins is see did I draw all pennies or all quarters. If drawn coins at zero equals equals drawn coins at one if the first two coins are the same and drawn coin at one equals equals drawn coins at two. If the drawn coin at the zero index equals the drawn coin at the one index which equals the drawn coin at the two index if each of these work increment yes. Now the last little bit that I'll leave you for this is you need to implement how to turn this into num trials. How do I do this? Not just once. I've only just done this once. If I attempt to run this, if I go yes divided by num trials and then I try and do a system .out.println of this, oh there are errors in there, where are you, num trails. I run this, I'm going to get zero. My probability of drawing three pennies is zero, zero or it errors. Where did that error come from, line 36, draw less than three index, oh index needs to be moved down below that I need to draw it different times. Oh you see that, I get probabilities now of zeros and then I saw a few ones in there. Then what happens here is I have to do this stuff because this has to run multiple times. Right now it's only running once, so yes might be zero or one divided by one, I'm only making one trial. So flash this out, continue building on this until you're getting one tenth. Best of luck.