You can do this using the built-in logistic distribution functions in R (e.g., rlogis(...)
, along with the truncdist
package.
library(truncdist)
location <- 0
scale <- 2
X <- rlogis(1000, location=location, scale=scale)
Y <- rtrunc(1000, spec="logis", a=-5,b=5, location=location, scale=scale)
par(mfrow=c(1,2))
hist(X, xlim=c(-10,10), breaks=30, freq=F, col="lightgreen")
hist(Y, xlim=c(-10,10), breaks=30, freq=F, col="lightblue")
If this is some kind of homework assignment, to show how truncated distributions are calculated, then I suggest you look at the code for the rtrunc(...)
function.