## Create discrete distribution with given probability density function
pdf <- function (x) { -0.5*x^2 }
dpdf <- function (x) { -x }
distpdf <- new("unuran.cont", pdf=pdf, dpdf=dpdf)
## Make generator (using method TDR)
unr <- unuran.new(distpdf, "tdr")
## Draw sample of size 100
x <- unuran.sample(unr, 100)Run the code above in your browser using DataLab