Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop an algorithm using a composition method to generate random variables fol

ID: 3282612 • Letter: D

Question

Develop an algorithm using a composition method to generate random variables following a triangular distribution as follows: f(x) = 1 + x ? ? 1 ? x ? 0, f(x) = 1 ? x ? 0 < x ? 1, and f(x) = 0 otherwise. You can generate the random number using the following LCG parameters. Zi = (a × Zi?1 + c)(mod m), where m = 224, a = 1140671485, c = 12820163, Z0 = 1234. (1) Generate 500 random variables and show them in the histogram plot. (2) Compare sample statistics with theoretic statistics, such as mean and variance.

Explanation / Answer

a<- 1130671485
m<- 2^24
  
(a*z[2]+c)*m

c<- 12820163
z <- vector(mode="numeric", length=5000)
z[1]<- 1234
  
for(i in 1 :5000) {
  
z[i+1]<- (a*z[i]+c)*m
  
  
}

hist(z,col="red")

#######

The result is