\(pdf= k/\lambda * (x/\lambda)^{k-1} * e^{-(x/\lambda)^k}\)
\(cdf= F(x) = 1-e^{-(x/\lambda)^k}\)
\(F^-1(x)= \lambda*((-log(1-u))^{1/k}\)

# 1. Define Inverse CDF function
Inverse_CDF_Weibull = function(n, k, lamda) {
   u <- runif(n)
   data <- lamda*((-log(1-u))^(1/k))
   return(data)
}

# 2. Generate realizations of the desired distribution
set.seed(209)
dataset <- Inverse_CDF_Weibull(n = 1000, 6, 3)
head(dataset)
## [1] 3.645106 2.833503 2.762492 2.755448 2.241425 2.949576
hist(dataset, prob = TRUE , col = "Misty Rose")

set.seed(209)
n = 1000
ka = 0
j = 0
y = numeric(n)
k=6
lam=3
fx=c()
fx2=c()
u= runif(n,0,1)
xe=c()
hasil=c()
for (i in 1:n){
j = j+1
x = runif(1)
xe[j]=x
fx[j]=(k/lam)*((x/lam)^(k-1))*exp(-(x/lam)^k)
fx2[j]=fx[j]/max(fx)
if (fx2[j] > u[j]) {
hasil[i]="accept"}
  else {hasil[i]="reject"}
}
result = data.frame(xe,u,fx2,hasil)
acc=subset(result,hasil== "accept")

plot(xe,u,pch=19)
points(xe, fx2, col="red", lwd=3)
points(acc[,1], acc[,2], col="blue", lwd=3)
legend("topright", legend=c("reject","accept" ,"fx/tx"), col=c("black", "blue","red"), lty=1:1, cex=0.8,bg="white",lwd=3)