And if you want from truncated normal, try this:
rtnorm <- function(n, mu=0, sigma=1, A=-Inf, B=Inf){
if(A>B) stop("\n B should be greater than A")
mu+sigma*qnorm(runif(n, pnorm((A-mu)/sigma), pnorm((B-mu)/sigma)))
}
rtnorm(1000, mu=35, sigma=4, A=1, B=41)
hist(rtnorm(1000, mu=35, sigma=4, A=1, B=41))
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Shuxia Yu" <ysxzh@163.com>
To: <s-news@lists.biostat.wustl.edu>
Sent: Friday, September 24, 2004 4:41 PM
Subject: [S] how to generate random number in a specific range
Dear all,
Would someone here like to point me how to generate a series random
number in a given range, e.g., 1 to 41? rnorm can't give what I
wanted ...
Thank you very much in advance!
Best wishes,
Jinsong
-------------------------------------------------------------------------------------
周杰伦在"第一现场"与你面对面
http://smspop.163.com/special/jay200408/index2.html--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu
with
the BODY of the message: unsubscribe s-news
|