 Hey guys, it's MJ the students actually and what I want to show you in this video is how to draw five cards From a normal playing card deck So what we have in my app is you click play and you can see that we have drawn some of those standard cards I've also got it so that you can click swap cards and you know possibly go for the flash But how do I draw these five cards? You know, how do I do so that every time I draw I'm getting different cards that do not repeat themselves That's the big thing. You don't want to eights of spades coming up. So how do we do it? Well, I'm going to show you the code What I do or what the general philosophy is is I'm going to be generating two random numbers for each card The first random number I call the suit. So what I do is like this is an Android studio I'm going to create a random variable using this code. So random s1 equals new random and then this random Value is going to be assigned to something which I call the suit So suit one is going to take a random number between One and four so it can be one two three or four this represents clubs hearts diamond spades So I'm going to create a random variable for that Then I'm also going to create another random variable for the number And this number is going to take a random value between one and thirteen and Then what I'm going to do is I'm going to say the card suit is equal to suit one and the cards number is equal to number one And because this is my first card. I simply assign these values But now when I come to the second card, I need to have a Little bit of a check and what I have done is I created a while loop So what I do, oh, what did I click there? Whoops, okay. Yeah, we back. Yeah, so what what I do is I create Exactly the same how did before create another random variable Between one and four and then another random variable between one and thirteen and I sign the cards but I then have this while loop and I say while suit one equals suit two and Number one equals num two. I want to generate another random variable and assign those cards So what this means is that let's say we get ace of spades here And then we get ace of spades again this while loop is going to say these guys are the same Let's generate another random variable and it's going to stay in this loop until we generate another card So remember but both the suits and the numbers have to be the same because we don't mind if we have two aces We have the ace of hearts and the ace of diamond and then what I'm going to do is I'm going to sign the card Now when I want to draw the third card, you can see my logic gets a little bit longer I need to make sure that suit three isn't the same as suit one and num three is equal to the same as num one But I also need to make sure that card three is not the same as card two and again I'm going to do the while loop When I draw the fourth card I need to make sure that the fourth card is not the same as the first card Not the same as the second card and not the same as the third card And then this is going to go in again and then finally for the fifth card You can see the logic does get a little bit long Because now if you check that it's not the same as the first not the same as the second Not the same as the third not the same as the fourth But essentially what we're doing is we're just having a while loop where we're Regenerating our random numbers re-assigning and then checking the condition and by doing that what we can achieve is We can achieve every time that we click play. We're going to see random cards coming up. No duplicates and There we go. That is how we assign Random cards from the 52 card deck and making sure that there are no duplicates Thanks guys so much for watching and check out my other videos around how I made this poker app Specifically how I did these little swap I'll show you guys how I did that in another video, but feel free to download this app The link is in the description below. Thanks guys so much for watching. Cheers