 So I'm just going to go through question six and question seven quickly because we ran out of time to do it in class. There was a few technical issues so I'll just go through it quickly now for anyone who was stuck on these questions. So we finished question five, we'll head to question six. Question six we talked about the random function so that was in the notes as well in the variables notes and it talks about this random method here so when you have a variable so here we have a double variable so that double is similar to float so just pretend that that's float and we say float r is equal to random and it's got the value n where n is any real number so if you give it the number seven this variable here will be allocated a number between zero and six so it won't go to seven because that number is exclusive. We can also do something like float r is equal to random three to eight so instead of giving it one number so if you give it one number it goes from zero to the number or if you give it a two inputs this is the range so between three and eight this number is inclusive so you can get the number three and this number is exclusive so really we can get we'll never get eight so if I print my value r I'm getting five point zero eight two because we've got a float if I wanted a whole number so an integer I would need to cast that as an int and we know that whenever we are dealing with integers so this part here as we saw before will give you a float value so if we're changing a float into an integer that means that we always round down and because we're rounding down that's the reason why we will never get to the number eight because even if we get seven point nine nine nine nine and we're dealing with integers it will round down so here we go six and every time we run it we'll get a different number so that's just a little introduction to the random feature and processing so now we want to use it to randomly generate lots of lines which have different lengths colors and different thickness of the lines as well so let's create our program in here just set everything up so I'm just going to set the size of the screen a bit bigger so everyone can see okay so lots of things we need to take into account here we talked a little bit about the difference between global and local variables as well if you try to do this one using global variables you find that it won't work so say if I want to create a global variable that contains the thickness of the lines so the stroke weight or we can't call it stroke weight I'll just call it stroke w is equal to we want it to be an integer a random number between and what do we want between zero and five so it would be zero and six if we were to make this a global variable as we're running through our code first thing we do is these global variables get initialized and we only get this one random value so if I was to go stroke weight stroke w the idea of this program is that every time draw loops around every time it loops a new stroke weight is allocated for a new line that's being drawn so we're not drawing a line yet but every time we loop through the stroke weight will change the location of the line the color will change and so every single time we need a new random number to be generated but what we're seeing is that this random number is only generated once when this variable is initialized so what we need to do is every time we run through draw we need to assign it a new random number so instead of giving it a value there I'm going to declare the variable up here globally so anywhere can access it and then every time I run through draw I'm going to give stroke w a new random value so now every time it's going to print a new value so we can test that just by throwing that in draw um oh that's the wrong print line and there we go so every single time we get a new number between zero and five so that's the type of thing we want to do so we've dealt with the stroke weight so the thickness of the line that's good now we need to look at the the color of the line so the stroke and also the different lengths of the line so that means that our x and y points for our lines will also need to change so I'm going to create some variables for that so I'm going to do x1 y1 x2 y2 you can declare your variables like this if it's all the same type and another one I want to do because we want a random color every time we want three random values for our RGB code so I want a different red a different green and a different blue every time so um let's set out our code first so we've got the stroke weight we also want the color of the line so the stroke we want it to be RGB and then our line is x1 y1 x2 y2 so that's all good but we need to give these variables some values so we've given let's do some code comments to make this a little nicer so set random values it's the first thing we should do and then this is the code to draw line we don't want that print line statement anymore so let's set our random values up here everything needs a new random value so x1 um x1 should get an integer random value and we want it to be anywhere over the x axis which will be from 0 to 600 but to keep our um our program dynamics so that it can change if we change the size of our screen I'm going to go from 0 to width okay um and I'm going to do the same thing for x2 I'm just going to do a bit copying and pasting to make this quicker the same for y1 except I want to do height and then again for y2 and I'm going to do the height so now we've dealt with having varying lengths um so we've done the strike weight we've done the coordinates and now we want to deal with the color so um our red in our RGB code oh that's something that I don't know if we did that um the red in our RGB code will be a random number between 0 and 256 um because the numbers for your RGB will go between 0 and 255 um and so we'll do 256 because we remember that this number is exclusive and we're going to do that for the g and the b so now every time draw runs it will go through every single one of these variables and it will assign it with a new random value given the range that you've allocated it so when we press play here it's probably just going to be a lot of um lines appearing on the screen it might be a little bit crazy but we'll see there we go so lots of different lines every time it's a different color different thickness different location um which is exactly what we wanted so that's good