Random Variate Generation.

Problem 7 Page 220.

Given the following CDF

#        0,              x < 0
#F(x) =  x^2             0 <= x <= 1   
#        1,              x > 1



# Step 1: Given the CDF we will perform Inverse Tranformation and we can equate the equation F(x) = R.

# Step 2: For the first and third the value of R =0 and R = 1.

# Step 3: Let us try to resolve the second between ranges 0 <= x <= 1

# R = X^2 
# X^2 = R
# X = sqrt(R) Equation 1


# Step 4, now changing the ranges from x to R since the equation is now interms of R

# Apply 0 and 1 in Equation 1, Range for R becomes 0 <= R <= 1

# Step 5, Running the random generator for 1000 samples in the range [0,1]

rand = runif(1000, 0 ,1)
out <- c()
for (i in rand) {
  X = sqrt(i)
  out <- c(out, X)
}

hist(out)