1 00:00:00,210 --> 00:00:01,110 ‫Welcome back. 2 00:00:01,140 --> 00:00:07,320 ‫In this video, we're going to look at random and we will look at random a little more when going to 3 00:00:07,320 --> 00:00:12,000 ‫the unity chapters and using video games or creating video games there. 4 00:00:12,000 --> 00:00:18,540 ‫We will need random because in video games, a random functionality is pretty interesting because, 5 00:00:18,540 --> 00:00:23,790 ‫well, you just want to have random situations which you can't be prepared to or for. 6 00:00:23,790 --> 00:00:29,310 ‫So let's go ahead and use a random dice. 7 00:00:29,310 --> 00:00:33,360 ‫So let's create a dice, which should be random, and we do the following way. 8 00:00:33,360 --> 00:00:39,840 ‫So we just say random, then the object name and we initialize it with new random. 9 00:00:40,980 --> 00:00:44,430 ‫Now I'm going to create another integer which I'm going to call num ise. 10 00:00:44,430 --> 00:00:53,220 ‫So the amount of ise that we have on our dice or on the showing dice and now I want to get ten different 11 00:00:53,400 --> 00:00:54,690 ‫random numbers. 12 00:00:54,690 --> 00:01:04,380 ‫Therefore I create an for loop here with i0i lower than ten I plus plus. 13 00:01:04,380 --> 00:01:11,610 ‫So that will simply loop it ten times and it will create ten random numbers. 14 00:01:11,610 --> 00:01:18,120 ‫So I'm going to set the num ise value to dice dot next. 15 00:01:18,570 --> 00:01:20,640 ‫And as you can see, there is an x double. 16 00:01:20,640 --> 00:01:31,830 ‫There is next and next returns a non negative random integer and it needs multiple entries so either 17 00:01:31,830 --> 00:01:36,030 ‫non or a max value or a range. 18 00:01:36,030 --> 00:01:37,980 ‫So min value and max value. 19 00:01:37,980 --> 00:01:41,550 ‫So what we're going to do is use min and max value. 20 00:01:41,550 --> 00:01:46,170 ‫So I want to have a number between one and seven. 21 00:01:46,170 --> 00:01:53,160 ‫So as you can see here, the max value, the exclusive upper bound of the random number returned max 22 00:01:53,160 --> 00:01:55,830 ‫value must be greater than or equal to min value. 23 00:01:55,830 --> 00:01:56,520 ‫That's important. 24 00:01:56,520 --> 00:01:58,080 ‫So that's the case for us now. 25 00:01:58,080 --> 00:02:03,510 ‫So the dice will have a value between one and six. 26 00:02:03,510 --> 00:02:06,270 ‫So seven is not included. 27 00:02:06,270 --> 00:02:10,800 ‫So as you can see, the exclusive upper bound, that's the seven. 28 00:02:11,040 --> 00:02:14,100 ‫Now let's simply write that onto the console. 29 00:02:14,100 --> 00:02:21,300 ‫So let's simply write the num ise onto the console and to keep the console open, I'm just going to 30 00:02:21,300 --> 00:02:24,390 ‫use console to read. 31 00:02:25,440 --> 00:02:26,610 ‫All right, let's check it out. 32 00:02:26,610 --> 00:02:34,140 ‫Let's see how random the numbers will be that we are six one, four, five, two and so forth. 33 00:02:35,060 --> 00:02:35,450 ‫All right. 34 00:02:35,450 --> 00:02:36,710 ‫And that's pretty much it. 35 00:02:36,720 --> 00:02:39,560 ‫That's how you can create random numbers. 36 00:02:41,830 --> 00:02:42,160 ‫All right. 37 00:02:42,160 --> 00:02:43,370 ‫Now, a little challenge for you. 38 00:02:43,390 --> 00:02:47,650 ‫Create a little program which has three random values. 39 00:02:47,650 --> 00:02:54,700 ‫So one, two or three for one, it should say something like, yes, for two, it should say maybe, 40 00:02:54,700 --> 00:02:56,170 ‫and for three, it should say no. 41 00:02:56,170 --> 00:03:00,610 ‫So it's pretty much like a fortune teller. 42 00:03:00,610 --> 00:03:04,720 ‫Which answers your question with yes, no or maybe. 43 00:03:04,720 --> 00:03:07,900 ‫And well, you can ask it anyway anything. 44 00:03:07,900 --> 00:03:10,930 ‫So please go ahead and try to build that program. 45 00:03:12,920 --> 00:03:13,310 ‫All right. 46 00:03:13,310 --> 00:03:14,570 ‫I hope you tried it. 47 00:03:15,020 --> 00:03:16,400 ‫And I'm going to call it. 48 00:03:16,490 --> 00:03:17,000 ‫Yes. 49 00:03:17,030 --> 00:03:17,420 ‫No. 50 00:03:17,420 --> 00:03:20,900 ‫Maybe random. 51 00:03:20,900 --> 00:03:21,390 ‫Yes. 52 00:03:21,410 --> 00:03:22,760 ‫No, maybe. 53 00:03:24,200 --> 00:03:27,460 ‫And I don't need all of that. 54 00:03:28,760 --> 00:03:32,880 ‫Just going to say that I need an answer. 55 00:03:32,900 --> 00:03:33,680 ‫None. 56 00:03:36,140 --> 00:03:37,460 ‫And if 57 00:03:40,550 --> 00:03:48,740 ‫answer num is equal to one, then do something. 58 00:03:49,520 --> 00:03:51,750 ‫And as you can see, answer numb is unassigned. 59 00:03:51,770 --> 00:03:53,810 ‫It's still empty. 60 00:03:53,960 --> 00:03:55,460 ‫So that's why it's not so happy. 61 00:03:55,460 --> 00:03:56,880 ‫We will set it in a second. 62 00:03:56,900 --> 00:03:59,980 ‫So if it's one, I want to write something like. 63 00:03:59,990 --> 00:04:00,770 ‫Yes. 64 00:04:03,840 --> 00:04:08,820 ‫LS if answer num is equal to two. 65 00:04:09,270 --> 00:04:10,580 ‫I want to write. 66 00:04:10,590 --> 00:04:14,100 ‫Maybe and otherwise. 67 00:04:15,000 --> 00:04:15,720 ‫No. 68 00:04:18,540 --> 00:04:19,170 ‫All right. 69 00:04:19,530 --> 00:04:21,120 ‫Now, of course, we need to set. 70 00:04:21,160 --> 00:04:24,600 ‫Answer num and answer num is going to be. 71 00:04:25,140 --> 00:04:25,790 ‫Yes. 72 00:04:25,800 --> 00:04:26,340 ‫No. 73 00:04:26,340 --> 00:04:28,590 ‫Maybe dot next. 74 00:04:30,900 --> 00:04:37,320 ‫And here we need to have values between one and three. 75 00:04:37,320 --> 00:04:39,060 ‫So we enter one and four. 76 00:04:40,710 --> 00:04:41,280 ‫Right. 77 00:04:41,400 --> 00:04:45,810 ‫So let's run it and see what's happened, what happens. 78 00:04:46,200 --> 00:04:47,790 ‫And it says no. 79 00:04:48,180 --> 00:04:49,500 ‫And I'm not very happy with that. 80 00:04:49,500 --> 00:04:51,840 ‫So I didn't even ask the question yet. 81 00:04:51,840 --> 00:04:57,840 ‫So maybe we add something like console dot red line. 82 00:04:59,710 --> 00:05:01,570 ‫And let's test it again. 83 00:05:03,450 --> 00:05:05,160 ‫And now you can enter your question. 84 00:05:05,160 --> 00:05:08,160 ‫Maybe we will tell to enter the question. 85 00:05:08,460 --> 00:05:15,360 ‫So please enter your question. 86 00:05:17,410 --> 00:05:20,160 ‫And of course, the question has to be a yes, no, maybe question. 87 00:05:20,280 --> 00:05:21,900 ‫Otherwise, it doesn't make sense. 88 00:05:22,470 --> 00:05:23,880 ‫So let's run it again. 89 00:05:23,880 --> 00:05:25,480 ‫Please enter your question. 90 00:05:25,500 --> 00:05:29,140 ‫Will I ever love. 91 00:05:29,160 --> 00:05:32,460 ‫So that's the standard question or will I ever be loved? 92 00:05:32,460 --> 00:05:34,960 ‫Or will I find my love or whatever? 93 00:05:34,980 --> 00:05:37,230 ‫That's what you see in the movies, right? 94 00:05:37,350 --> 00:05:39,050 ‫And let's enter. 95 00:05:39,060 --> 00:05:40,110 ‫And it says Yes. 96 00:05:40,110 --> 00:05:41,220 ‫Oh, how beautiful. 97 00:05:41,250 --> 00:05:41,880 ‫That's great. 98 00:05:41,880 --> 00:05:43,790 ‫Thank you very much, fortune teller. 99 00:05:43,800 --> 00:05:44,850 ‫I'm so happy. 100 00:05:45,120 --> 00:05:47,230 ‫All right, so let's run it again. 101 00:05:47,250 --> 00:05:53,670 ‫Of course, you could create a wild loop here where you can enter questions all the time, but I just 102 00:05:53,670 --> 00:05:56,010 ‫have to restart the program in my case. 103 00:05:56,010 --> 00:06:01,380 ‫So the next question, will this video be great? 104 00:06:03,710 --> 00:06:06,830 ‫And it says maybe well, at least maybe I can live with that. 105 00:06:06,860 --> 00:06:08,990 ‫I, I hope you like it. 106 00:06:08,990 --> 00:06:09,770 ‫I hope it's great. 107 00:06:09,770 --> 00:06:14,210 ‫I hope you could manage to finish this little program as well. 108 00:06:14,300 --> 00:06:20,300 ‫And yeah, so now you have a little program that you can show your friends and see you in the next video.