1 00:00:00,000 --> 00:00:00,000 Hello, Tim. 2 00:00:00,000 --> 00:00:05,000 Today I will show you how you can generate random numbers from the lesson about math class. 3 00:00:05,000 --> 00:00:11,000 You already are aware that you have mass random method, but today I will show you another way to create 4 00:00:11,000 --> 00:00:12,000 random number. 5 00:00:12,000 --> 00:00:15,000 It can be that your program needs some random number. 6 00:00:15,000 --> 00:00:21,000 For example, you want to implement dice game and when player wants to roll the dice you need to generate 7 00:00:21,000 --> 00:00:22,000 random number. 8 00:00:22,000 --> 00:00:24,000 Let's take a look how you can do this. 9 00:00:25,000 --> 00:00:27,000 You need to create new object of type. 10 00:00:27,000 --> 00:00:31,000 Random eclipse will suggest you to import class Java.util.random. 11 00:00:32,000 --> 00:00:35,000 This class is used to generate pseudo random numbers. 12 00:00:35,000 --> 00:00:40,000 I don't want to dive into the details of how pseudo random numbers are generated, and why they are 13 00:00:40,000 --> 00:00:43,000 called pseudo random, but not just random. 14 00:00:43,000 --> 00:00:49,000 To be honest, this information won't help you in the nearest future, and it is a bit complicated for 15 00:00:49,000 --> 00:00:50,000 understanding right now. 16 00:00:51,000 --> 00:00:57,000 In short, it is obvious that absolutely random number is impossible to generate, so usually some algorithm 17 00:00:57,000 --> 00:00:59,000 is used to generate sequence of numbers. 18 00:01:00,000 --> 00:01:06,000 That's why these numbers can't be called completely random, because there is predefined algorithm in 19 00:01:06,000 --> 00:01:08,000 place which generates the sequence. 20 00:01:09,000 --> 00:01:14,000 After you created instance of random type, you can use its methods to generate either int, float, 21 00:01:14,000 --> 00:01:16,000 double long or boolean. 22 00:01:16,000 --> 00:01:18,000 Just type next int. 23 00:01:18,000 --> 00:01:24,000 In case when you want to generate pseudorandom int or next double in case when you want to generate 24 00:01:24,000 --> 00:01:26,000 pseudorandom double, and so on. 25 00:01:26,000 --> 00:01:32,000 If you want to generate ints within the specific range, just pass integer to the next int method. 26 00:01:32,000 --> 00:01:36,000 In this case, we will generate random number from 0 to 99. 27 00:01:37,000 --> 00:01:42,000 If you want to generate integers from 1 to 100, just write something like this Ethz. 28 00:01:42,000 --> 00:01:46,000 During your homework, you will be asked to generate random numbers for some tasks. 29 00:01:46,000 --> 00:01:49,000 And now you know how to do this. 30 00:01:49,000 --> 00:01:51,000 Thanks a lot for your attention. 31 00:01:51,000 --> 00:01:53,000 See you in the next lesson. 32 00:01:53,000 --> 00:01:53,000 Ay ay ay ay ay ay.