Hello, Tim.
Today I will show you how you can generate random numbers from the lesson about math class.
You already are aware that you have mass random method, but today I will show you another way to create
random number.
It can be that your program needs some random number.
For example, you want to implement dice game and when player wants to roll the dice you need to generate
random number.
Let's take a look how you can do this.
You need to create new object of type.
Random eclipse will suggest you to import class Java.util.random.
This class is used to generate pseudo random numbers.
I don't want to dive into the details of how pseudo random numbers are generated, and why they are
called pseudo random, but not just random.
To be honest, this information won't help you in the nearest future, and it is a bit complicated for
understanding right now.
In short, it is obvious that absolutely random number is impossible to generate, so usually some algorithm
is used to generate sequence of numbers.
That's why these numbers can't be called completely random, because there is predefined algorithm in
place which generates the sequence.
After you created instance of random type, you can use its methods to generate either int, float,
double long or boolean.
Just type next int.
In case when you want to generate pseudorandom int or next double in case when you want to generate
pseudorandom double, and so on.
If you want to generate ints within the specific range, just pass integer to the next int method.
In this case, we will generate random number from 0 to 99.
If you want to generate integers from 1 to 100, just write something like this Ethz.
During your homework, you will be asked to generate random numbers for some tasks.
And now you know how to do this.
Thanks a lot for your attention.
See you in the next lesson.
Ay ay ay ay ay ay.