 However, if you are interested in generating a discrete random variable, there is actually a simpler method ok. Let us see how that how does that work. Suppose let us say your x takes values x 1, x 2, x 3 like that ok and it is a discrete random variable and assume that x 1 is the smallest and x 2 is the next smallest and x 3 is the next smallest like this the possible values taken by this my random variable they are arranged in increasing order. And suppose x has a CDF of f and I want to find the probability that my random variable u takes value between f x i and f x i plus 1 ok. Let us visualize this ok. Let us assume that my values are x 1, x 2, x 3 like this and this being a discrete random variable my jumps will happen at this points only ok. Let us let us say and let us say jump will happen somewhere here and now what I am asking I have a random variable u, u is taking value between f x i and f x i plus 1 ok. Let us maybe what I will do is ok let us do this this one like this, this is x i where this jump is happening ok. Let us let us do this and this is x i and this point is x i plus 1. So, what is this x i? This is the value ok. Now, I am asking what is this point here? This is f x i and what is this point here? This is x i plus 1. Now, I am asking u is some uniform random variable with parameter 0 1. What is the probability that it lies in this value? So, probability that u is between f of x i and f of x minus y I know that this is nothing but f of x i plus 1 minus f of x i for uniform random variable everybody agree with me and now if you look into the difference between f of x i plus 1 and f i how much is this jump? The mass that the point x i plus 1 have right. So, that is the point. So, this is going to be exactly equals to x i plus 1. So, we can explore this property that if you generate an uniform random variable the probability that it takes value between f of x i and f of x plus 1 is exactly equals to probability of x i plus 1 right and we can use this property to generate random variable which has this probability mass function ok. Let us say this is like now this is p of x 1 p of x 2 like this is my probability mass function right and I want my x y's x 1's to appear with probability p x 1 x 2 to appear with probability p x 2 like that. Now, what we are saying is we can get that probability using an uniform random variable in this fashion everybody agree like how this is working ok what is the process? Now, this is the property we understood the property we want to exploit it. Because I have been given ok I have been given x and I have been told that it takes value x 1 x 2 like this and I have been asked to generate to generate samples satisfying this pdf sorry this cdf this is a discrete this cdf. So, once you give me cdf do I know the probability mass function yes right if I know f I know p also. Now, what I will do is I will take a uniform random variable generate a sample and see whether where it falls it falls between which of this interval whether it falls here, here, here and if it happens to no I will check basically this intervals like which which of this intervals it will follow like I can divide this into intervals right like this. So, what is the range of my cdf value? What is the value it my cdf can take? 0 to 1 right. So, this value is maximally going from 1 0 to 1 and I have divided them based on the jumps and let us say this is like x i plus 1 and this is x i this is f of x i and now you generate you and say between it is going to be between 0 1 see that where it falls it falls in this category in this category in this category on this category and if it falls in this category in this block you are going to take your value x to be x i plus 1 and then the samples you got they are going to follow your required cdf. Now, let us work out this particular example we have here. Is the basic idea clear how this is being generated? Now, I want to generate x which is binomial with parameter 4 and 5 by 8. So, what are the possible outcomes of this binomial random variable? It is going to take what values? It is going to take 0 1 2 3 4 and this is a binomial random variable I know its probability mass function right. So, what is the probability that it is going to take value i? 4 choose i 5 by 8 i 3 by 8 4 minus i and from this can I found its probability sorry cumulative density function I can find out what is f it is taking value i equals to 0 1 2 3 4. So, I basically have so, it is like this this like this maybe I will just call it 0 1 2 3 4 and this is 1. Now, what I am going to do is I generate uniform random variable if it happens to be between 0 to 0.02 I will take the value of x to be 0. If it happens to be between 0.02 0.152 I will take 1. You know how this 0.02 0.12 are coming from right yeah cdf values. This is a probability that it is going to take value 0 and this is cdf at 0 this is cdf at 1 cdf at 1 cdf at 2 like this. If it is going to be between 0 0 to 0 point you take 1 if it is between 0.02 0.152 take 1 like that and if it is at going to be between 0.847 it is going to be like this. So, if you let us say you have n samples let us say u 1 u 2 up to u n you take u 1 you see which of this condition satisfy can more than one condition satisfy here no right it only one condition satisfy and whichever it is it is going to be one of them call that as x 1 and similarly next you take u 2 see which one of this condition satisfied to call that x 2 like that. Now, you take u n and see which condition satisfy now. Now, this x 1 x x n c have they are going to have what cdf by normal with parameter 4 and 5 by 8 is that clear right. Once it is a discrete case it is pretty easy to generate you are you do not need to even worry about inverting this f f could be complicated I mean if it is very hard to invert even this discrete like this right functions. So, you can just apply this method ok. Now, we will just talk about one indirect method how to do it for the indirect method ok. So, we need to apply some tricks here when it is. So, discrete methods we are pretty sure like how to do using this only thing is now continuous case continuous case the only simple things we did like gamma generation chi square with even number of degrees of freedom and we also talked about Gaussian distribution, but for the continuous case the pdf can be arbitrary how to generate that ok. Now, let us initially let us take my distribution to be taking only value in the interval 0 1 and let us assume that it looks like this its curve looks like this. So, it is a range is only between 0 1. Now, let us again try to see that we can generate this distribution using some uniform random variables. I am now starting with two uniform random variables u and i which are independent and let us say f is given pdf and f is given and I will find out the maximum value of that pdf. So, in this case right if you take this pdf the maximum value is here this is what I call that as c. Now, let us see I am interested in evaluating this function probability that u is less than or equals to y and capital U is less than or equals to 1 by c of f of v ok and this is for a given y you take some value y and now try to evaluate this this probability. Now, how to evaluate this probability? Since u and v are independent uniform what is their joint distribution? What is the possible value that joint distribution can take? Now, u and v right because they are independent it is nothing, but u of v u of v and u of v right because u and v are independent and now they are also uniform I know that this is going to take value 1 this is going to take value 1 if my u v are in the interval of 0 1 right. So, this it this this joint distribution can also take value 0 1 between 0 1 only right it cannot take anything else because both f of u and f of v takes value only between 0 1 or I would say not value it is exactly equals to 1 right. Uniform distribution its pdf is constant 1 in the in the when when both u and v they are less than or equals to 1 equals to 1 or maybe I should write it like this and 0 otherwise. So, I have just used that property and now I am integrating it first one is between 0 to y and the second one is between 0 to f of x v by c. Now, if you simplify this you will get that this is nothing, but 1 by c is anyway constant and this is 1 by c times probability that x is going to be less than or equals to 1. Everybody agrees with this calculation I am just simply using the property of uniform random variable nothing else. So, if you have not digested just again verify this. Now, this is true for any y this this is true for I will particularly take y equals to 1. When y equals to 1 what is the relation I am going to get? Now concentrate on this and this relation when y equals to 1 v less than or equals to 1 that means, v can only be between less than or equals to 1 right. So, that will become marginal for me and when x is less than or equals to y here x I am assume that its range can be only between 0 or 1. What is the probability that x can be less than or equals to 1? It is going to be 1. So, that is simply becomes 1 by x 1 by c here. So, because of when I take y equals to 1 this has to be true for every this relation has to be true for everyone when I take y equals to 1 what the relation I get is probability that u is less than or equals to 1 by c f of v is exactly equals to 1 by c. Which one? Yes no all we are assuming is it is taking value between 0 and 1? No no no this just for representation we put it can be anything it could be even like something like this it could be anything. So, from this exercise what we know is if I have a two uniformly distributed random variable u and v for any f whatever the underlying c d f we are talking about this relation holds that is the crucial thing that we have just derived it does not depend on c like you can put any value here that is fine nothing specific that why we took only thing is we took a c to make sure that this ratio right here is less than 1. If you take something like c to be less than 1 this ratio could exceed 1 and that is a not a good case for us ok. Now what we did if you now look into this so in summary what we did we just showed that probability that u is less than or equals to v u less than or equals to v 1 by c f of v is 1 by c x less than or equals to v that is what we said sorry this is into, but we said that, but we have a relation this 1 by c is nothing, but probability that u is less than or equals to 1 by c f of v right this is the relation we have gotten. Now what I do is probability x is less than or equals to v and I take this in the denominator here I just take this in the denominator side here and I will get this relationship and now if you look into this this is nothing, but now this is like I can treat it like a conditional probability. Probability that u is less than or equals to u and probability that u is less than or equals to 1 by c f of v given that u is less than or equals to 1 by c f of v. Everybody agree with me? So, now I want to explore this relation I what I was able to show what I have derived is probability that x is less than or equals to y is dependent on u and v and c in this fashion ok. Now let us see if we can generate an algorithm based on this simple idea all I need is two random variables u and v which are uniform independent and you have to give me the CDF according to which you want your data. So, first step in the algorithm is generate uv sample iid uniform distributed and then check that if this u is less than or equals to 1 by c f of v that is a conditional part you are going to check is if u is less than or equals to 1 of u. If this this true if this condition is true what is this value? This if this condition is true then this joint part does not matter right what matters is only u is less than or equals to y. If this is true then it is simply probability that v is less than or equals to y. So, then in that case I can simply take this x to be equals to that is it. So, now you see that whenever this condition is met those samples I will take it as x otherwise I will go back and regenerate ok. Just let us see how this works suppose let us say you generated u1 and v1 and then what you are going to do is you check whether your u1 is less than or equals to 1 by c f of v1. If true you take your x to be v1 else you go back and do this and keep doing that and in some cases you are going to this condition becomes true and and another thing see like you have asked why is this c to be taken maximum right. This condition u to be less than or equals to 1 by c f of v this is guaranteed to be less than 1 only when you take c to be max value. If you do not take it max value this is not guaranteed to be less than 1 and now you will get samples whenever this condition is met those samples you collect and those samples are guaranteed to be following your required cdf function and this is what called indirect method. So, one last thing is if you want to get rid of the assumption that your pdf is between 0, 1 all you need to do is instead of c you redefine your function m and then repeat the same process. Then this will also give you a random variable which has your required distribution f, but without requiring that requiring it to be taking value between 0, 1. Okay. So, let us stop here.