accrejgamma py from math import exp gamma log from numpy random import rand alpha lam lambda xlam *alpha **alpha - exp(-lam* )gamma alpha lambda exp - *xc found false while not found log(rand ())/ if * ( )*rand (< ( )found true print (xsimulating random vectors and processes techniques for generating random vectors and processes are as diverse as the class of random processes themselvesseefor example[ we highlight few general scenarios when xn are independent random variables with pdfs fi nso that their joint pdf is (xf ( fn (xn )the random vector [ xn ]can be simply simulated by drawing each component xi fi individually -for examplevia the inverse-transform method or acceptance-rejection for dependent components xn we canas consequence of the product rule of probabilityrepresent the joint pdf (xas (xf ( xn ( ( fn (xn xn- )( where ( is the marginal pdf of and fk (xk xk- is the conditional pdf of xk given xk- xk- provided the conditional pdfs are knownone can generate by first generating thengiven generate from ( )and so onuntil generating xn from fn (xn xn- markov chain the latter method is particularly applicable for generating markov chains recall from section that markov chain is stochastic process {xt that satisfies the markov propertymeaning that for all and the conditional distribution of xt+ given xu tis the same as that of xt+ given only xt as resulteach conditional density ft (xt xt- can be written as one-step transition density qt (xt xt- )that isthe probability density to go from state xt- to state xt in one step in many cases of interest the chain is time-homogeneousmeaning that the transition density qt does not depend on such markov chains can be generated sequentiallyas given in algorithm