Generation of distribution with given mean, standard deviation, lower and upper bounds How to generate distribution in R, members of which are inside bounds and mean with SD are fixed?
I just need a distribution which will fit in the supported criteria. This will be used for simulating results from other study for comparison with data I have.
I need something like this:
rBootstrap<-function(n,mean,sd,lowerBound,upperBound){
   ...
}

which result of d <- rBootstrap(100,50,10,30,100)) had 
min(d) $\approx$ 30, 
max(d) $\approx$ 100, 
mean(d) $\approx$ 50, 
sd(d) $\approx$ 10.
The best result I had achieved is:
rBootstrap<-function(n,mean,sd,lowerBound,upperBound){
    data <- rnorm(n,mean,sd)
    return(data)
}
summary(rBootstrap(100,50,10,30,100))
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  26.18   41.27   47.29   48.43   55.06   71.82

and it is very far from desired. I had tried several others but without success. 
Is it possible to do this at all and in R in particular?
 A: There typically is more than 1 distribution with the given set of parameters (mean, sd, upper and lower boundaries). So there are several ways of doing this.
Since you are looking for a continuous distribution that is bounded, Wikipedia suggests among others, the beta distribution.
If I recall correctly, there is a parametrisation of the beta-distribution in terms of the mean and variance. So if you transform your boundaries to [0,1] and apply the same transformation to your mean and sd, then generate data with the beta distribution (rbeta), which guarantees that your data will be within [0,1], and transform back, you should get reasonable results.
BTW: why do you call this bootstrap? Apparently, you're just trying to sample from a distribution?
Edit: Yurij used the suggestions from this answer and the comments, resulting in this function:
rBootstrap<-function(n,mean,sd,lowerBound,upperBound){
    range <- upperBound - lowerBound
    m <- (mean-lowerBound) / range #mapping mean to 0-1 range
    s <- sd / range #mapping sd to 0-1 range
    a <- (m^2 - m^3 - m*s^2)/s^2 #calculating alpha for rbeta 
    b <- (m-2*m^2+m^3-s^2+m*s^2)/s^2 #calculating beta for rbeta
    data <- rbeta(n,a,b)  #generating data
    data <- lowerBound + data * range #remaping to given bounds
    return(data)
}

A: If you want to generate data from a distribution determined by your data, but not a straight bootstrap, then look at the logspline package for R.  You can set a minimum and a maximum and have the general shape of the distribution follow from the data (would give similar mean and sd, but not guarenteed to be exact).  You can then generate new random observations from the fitted distribution using the rlogspline function.
A: Found a prepackaged solution here. There is a distributions called "truncated" which has upper and/or lower limit. One of them is truncated normal distribution.
There are a couple of functions designed to sample from a truncated normal distribution:


*

*rtruncnorm(100, a=-Inf, b=5, mean=3, sd=2) in the truncnorm package

*rtnorm(100, 3, 2, upper=5) in the msm package

A: Sadly this won't do you much good in R, but since I think it's faintly on topic for the general question, this link on my blog: http://confounding.net/2010/12/01/randomly-generating-a-truncated-normal-distribution/ is the code to generate normally distributed data with fixed upper and lower bounds.
