Welcome to the last session in our final hacking advanced level class, which is basically about prime
numbers.
And in this session, we are going to learn about how to find out how to create or generate our prime
numbers.
So the first thing we would be doing is in our program that we would be creating.
We define some functions.
One is, is crime trial, the I.V., which uses the trial division algorithm to return to the number
two.
It is a primer fall to the number two.
It does not apply.
The next thing we want this time of function, which uses Sèvres of an algorithm to generate the prime
numbers.
We want the rubbin function, which uses the algorithm to check whether the number of pastorate is applying.
And this algorithm, unlike the trial division algorithm, can work equally or quickly on a very large
number of this function called not directly, but rather than is brain function.
So we have another function that this is is called when the user must determine whether the large integer
is prime or not, and the last one is generated large by Britain's or large prime number.
That is hundreds of digital.
So over here, we will start creating this particular code so quickly.
My first of all, C five, and then we will fight and we would first do here and import of math and
require random.
Then the first thing we will be defining is the is prime trial division, which takes numbers as the
parameters and this returns true if numbers are prime number otherwise fours and uses the trial division
algorithm for testing the primatology.
So all numbers then two are not right.
So if we check over here directly, we open the function here like this and check if the numbers to
it is less, then do we simply return the value false and then see if number is divisible by any other
number up to the square root of NUM.
So for that we are an affordable thing for I in the range of from to fill in and you take the square
root of num plus one and in this for loop which if num modulo I is equal to zero then return false otherwise.
Finally we say return true.
Now after this function we require the next function that this prime sieff, which takes up an amateur
of size.
And inside of this we return the list of prime numbers calculated using this Sèvres of the algorithm.
So over here we see this is equal to say true, multiplied by the Sèvres size.
Then we say, see that the index zero is equal to force.
That zero and one are not prime numbers.
Hence we have done this and the next we take C that the index one is equal to force, then to create
the C, C for I in the range of starting from two again in my thought square root we take your C size
plus one and here we take all variable pointer which is equal to I multiplied by two and save.
While the value of pointer is less than the value of C size, then you say see the index of pointer
is equal to false and C point of plus is equal to the value of right.
After this we compiled a list of prime numbers by saying over here we say primes is equal to open close
bracket.
And for I in the range of C size we say if your C that the index of Pi is equal to true, then we say
primes dot append in that the value of I finally will return the value of primes from this function.
Then next we have a definition for Robin Miller, which is another function, that is Robin Miller,
which takes again another parameter.
And in this it returns true if numbers are prime number.
So over here we check if num modulo two is equal to zero or we use numbers less than two, then we see
the likely return force that is.
Robin Miller doesn't walk on even in details, so next we check if the value of NAM is equal to three,
then we see the value through and said X is equal to, say, minus one.
And this is equal to say zero, then we say while it's modulo two.
Which is equal to zero, then keep having it until it is over.
So we say X is equal to s double slash two and the plus is equal to one, then result, say, four trials
in the range of five.
We tried to force the numbers primally three to five times.
So we say here A is equal to we use random thought.
We use around the range of say to Bill number minus one and we take V is equal to power of eight if
no.
After which we check if V is not equal to one.
This, this does not apply.
V is equal to one.
So we say here is equal to zero and then we say V not equal to number minus one.
We check if I is equal to three minus one we return here.
False.
Then we have the l thought you would be saying I was two plus one, we will stop the double strip to
modulo the value of numbers.
And finally, we use a written statement.
Now, most of the time, we can quickly determine if no is not a crime by dividing the first few dozen
prime numbers.
Now, this is a clear cut and Robin Miller does not detect all compositions.
So over here, we define first Cee Lo on score rhymes, which is a constant and that is equal to we
call here Prime Sèvres and Farse Hundred.
Now this time, C is a function that we have defined here.
So let us take it in the same case that we have defined, not after this particular definition we define
here and is prime matter, which takes no parameters.
And this returns true if no subprime.
No, this function does a quick subprime no check before calling Veerappan.
So here we do if synonomous less than two we say return false.
And after this we say for subprime in your.
Low price, then we check, if no more prime comes to zero, then we see little falls.
If all else fails, then call the Robin Miller to determine if no.
So after this, then we see.
The value of Robin Miller with passing that number and once you have done that, then the last thing
we are supposed to define is see, generate the large.
Prime, what we are giving here, a key size that's equal to seven zero two four.
And in this we are returning our random prime number that is key size.
But in sizes, we are saying here, while true, we define the number is equal to the random dog or
random range, that is two multiplied by the size minus one, and then giving you two multiplied by
the size.
And then we check if his prime force, the number that is, if it is true, then you are returning the
value of numbers.
Now if you want to see the output, you will have to enter something in the interactive shell.
First thing is we will save this and we will see it again in the drive in our advanced level course.
Let's give this prime number and let us save this.
Now, let us go back to the interactive shell here.
And in this whole thing is we will import the prime number.
Have made a mistake.
Let's go back here now.
What is that?
It is flying.
Steve is not defined.
OK, so we have this defined here flying.
Steve and I be using it.
Let's see below.
Also, it is defined properly, no issues.
Fine, so Sèvres is not defined.
OK.
Made a mistake in defining it.
Let's have a look this month that is over sea size that we are finding in the plains.
So let's just look at the school that we have defined in the metal flying.
SEIFE So here we are defining force to see if that is equal to true, multiplied by the sea size.
And then we are using, you see, the zettl that is equal to force, I'm adding this one is also equal
to force.
OK.
So this is where we have to find this, let's save it and again, try to execute it.
So this is working out and then we say, frim God, now let's call Lemaitre.
That is our.
Generate large size.
So we call this material to generate some large prime number, which is this particular value.
Similarly, if we see prime numbers, DOT, we call is bright and we pass some number to find out if
it is a crime.
But it is a very large number.
It gives us the value falls.
Similarly, we say prime number is prime.
Let's pass the small number to it again.
Value comes first.
So importing this model lets you generate the large numbers using we generate large brain function and
it also ties or lets us pass any number, large or small, to the prime function to determine whether
it is a PIN number.
So finding out a very large number, if it is a prime number or not, is very much easy if we use this
particular code that we have created here.
So with this, we have completed the python having advanced level codes where we have seen a lot of
examples on different types of Hocking's and how the example basically Vogues with many new functions
that we have used.
So you can try out all those functions or all those examples that we have done, and then the next thing
we will move on with some different concepts.
So that's it from this session of generating large prime numbers of Python.
Thank you very much.