Welcome back.
Last time I was talking about how to seat the random generator using time, right.
Let's check it out now.
To see the random number generator, I need an integer number because a seed function expects an integer.
OK, so how can I get the current time as an integer?
It's a time value, not an integer.
So how can I get it?
OK, so if you go here, it will display the current time as a Unix time.
By the way, if you don't know what a Unix time is, you may read more about it by checking out the
resources.
OK, as you can see here, Unix time is an integer, so I can use this one.
So how can I get the current Unix time go.
OK, let me go to the Goldman documentation.
And if you go to the documentation of the time package, you can find the method that's returning the
time as Unix time.
Let me show you.
Here it is.
As you can see, it returns the time in seconds as an indicator for value, cool, I can use this hoer
there is another interesting function here.
You know, this one returns the unique time in nanoseconds instead of seconds.
Huge difference since nanoseconds are changing much faster than seconds.
So this will produce a better seat number.
By the way, this is a method of the time type.
We talk about this a lot of times before.
So this means that I need to create a time value first, remember that I can create a time value by
using the now function of the time package.
Right.
So in summary, it looks like this time now returns to current time is a timely.
So I can call methods on that time, Mel.
When I do that, the Eunuch's nanometre to return the current time is Unix time in nanoseconds and as
an integer.
Then I will use that Ever-changing Unix time number to see the round package so that each time I run
the program, the seat number will change.
And in turn when I call the INS and function, it will generate a random number depending on that seat
number.
So this means that the program will generate a different set of random numbers each time it runs coding
time as usual.
Now, let's apply this knowledge to our program.
OK?
First, I'm going to call the function to create a new time value by assigning it to the T variable.
As you can see, this function returns a time value, right?
So now I'm going to seed it with the current Unix time like this.
That's unique now, cool, as you'll see in a second, that it will generate a different set of random
numbers each time I ran the program.
Now, let's try running the program a few times now, each time I run it, it produces a different set
of random numbers, right?
Cool randomly, it finds my guest number Justan.
As soon as it finds it, it stops the loop immediately.
So this program will be the best algorithm of the lucky number game that I'm going to show you.
By the way, I can also move this time that Nakul from here.
To hear so I don't need to use a variable for that.
This works because here it calls the Unix nanometre on the time value that is returned from time that
now whether you are using a variable or not makes no difference.
But typing it like this looks better to me.
OK, so for now, you learn how we can generate random numbers properly by using a seat number in the
next lecture, I'm going to start building the actual economic program.
See you there.