Skip to content
Prev 173396 / 398506 Next

Pseudo-random numbers between two numbers

Because of a mistake I made in copying code into email, there has
been confusion (expressed in some private emails). Hence the
corrected version is appended at the end.
On 11-Mar-09 00:05:26, Ted Harding wrote:
Corrected version:
------------------

truncnorm<-function(HowMany,Min,Max,mean=0,sd=1){
  qnorm(runif(HowMany, pnorm(Min,mean,sd), pnorm(Max,mean, sd)),
        mean, sd)}
Sample <- truncnorm(100000,-1,2.5)
H <- hist(Sample,breaks=100)
u0<-(-0.975)+0.05*(0:69)
yy<-dnorm(u0)
du<-min(diff(H$breaks))
Y <- 100000*yy*du/(pnorm(2.5)-pnorm(-1.0))
lines(u0,Y)


Apologies for the error.
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 11-Mar-09                                       Time: 19:48:12
------------------------------ XFMail ------------------------------