‫Welcome back.
‫In this video, we're going to look at random and we will look at random a little more when going to
‫the unity chapters and using video games or creating video games there.
‫We will need random because in video games, a random functionality is pretty interesting because,
‫well, you just want to have random situations which you can't be prepared to or for.
‫So let's go ahead and use a random dice.
‫So let's create a dice, which should be random, and we do the following way.
‫So we just say random, then the object name and we initialize it with new random.
‫Now I'm going to create another integer which I'm going to call num ise.
‫So the amount of ise that we have on our dice or on the showing dice and now I want to get ten different
‫random numbers.
‫Therefore I create an for loop here with i0i lower than ten I plus plus.
‫So that will simply loop it ten times and it will create ten random numbers.
‫So I'm going to set the num ise value to dice dot next.
‫And as you can see, there is an x double.
‫There is next and next returns a non negative random integer and it needs multiple entries so either
‫non or a max value or a range.
‫So min value and max value.
‫So what we're going to do is use min and max value.
‫So I want to have a number between one and seven.
‫So as you can see here, the max value, the exclusive upper bound of the random number returned max
‫value must be greater than or equal to min value.
‫That's important.
‫So that's the case for us now.
‫So the dice will have a value between one and six.
‫So seven is not included.
‫So as you can see, the exclusive upper bound, that's the seven.
‫Now let's simply write that onto the console.
‫So let's simply write the num ise onto the console and to keep the console open, I'm just going to
‫use console to read.
‫All right, let's check it out.
‫Let's see how random the numbers will be that we are six one, four, five, two and so forth.
‫All right.
‫And that's pretty much it.
‫That's how you can create random numbers.
‫All right.
‫Now, a little challenge for you.
‫Create a little program which has three random values.
‫So one, two or three for one, it should say something like, yes, for two, it should say maybe,
‫and for three, it should say no.
‫So it's pretty much like a fortune teller.
‫Which answers your question with yes, no or maybe.
‫And well, you can ask it anyway anything.
‫So please go ahead and try to build that program.
‫All right.
‫I hope you tried it.
‫And I'm going to call it.
‫Yes.
‫No.
‫Maybe random.
‫Yes.
‫No, maybe.
‫And I don't need all of that.
‫Just going to say that I need an answer.
‫None.
‫And if
‫answer num is equal to one, then do something.
‫And as you can see, answer numb is unassigned.
‫It's still empty.
‫So that's why it's not so happy.
‫We will set it in a second.
‫So if it's one, I want to write something like.
‫Yes.
‫LS if answer num is equal to two.
‫I want to write.
‫Maybe and otherwise.
‫No.
‫All right.
‫Now, of course, we need to set.
‫Answer num and answer num is going to be.
‫Yes.
‫No.
‫Maybe dot next.
‫And here we need to have values between one and three.
‫So we enter one and four.
‫Right.
‫So let's run it and see what's happened, what happens.
‫And it says no.
‫And I'm not very happy with that.
‫So I didn't even ask the question yet.
‫So maybe we add something like console dot red line.
‫And let's test it again.
‫And now you can enter your question.
‫Maybe we will tell to enter the question.
‫So please enter your question.
‫And of course, the question has to be a yes, no, maybe question.
‫Otherwise, it doesn't make sense.
‫So let's run it again.
‫Please enter your question.
‫Will I ever love.
‫So that's the standard question or will I ever be loved?
‫Or will I find my love or whatever?
‫That's what you see in the movies, right?
‫And let's enter.
‫And it says Yes.
‫Oh, how beautiful.
‫That's great.
‫Thank you very much, fortune teller.
‫I'm so happy.
‫All right, so let's run it again.
‫Of course, you could create a wild loop here where you can enter questions all the time, but I just
‫have to restart the program in my case.
‫So the next question, will this video be great?
‫And it says maybe well, at least maybe I can live with that.
‫I, I hope you like it.
‫I hope it's great.
‫I hope you could manage to finish this little program as well.
‫And yeah, so now you have a little program that you can show your friends and see you in the next video.