[R] simple random number generation

Moshe Olshansky m_olshansky at yahoo.com
Fri Jul 25 04:57:37 CEST 2008


Or, as suggested by Duncan Murdoch, 

qnorm(runif(500,pnorm(-1.5),pnorm(1.5)))


--- On Fri, 25/7/08, jim holtman <jholtman at gmail.com> wrote:

> From: jim holtman <jholtman at gmail.com>
> Subject: Re: [R] simple random number generation
> To: "dxc13" <dxc13 at health.state.ny.us>
> Cc: r-help at r-project.org
> Received: Friday, 25 July, 2008, 12:43 PM
> Generate more than you need and then just keep 500 of them:
> 
> > x <- rnorm(3000)  # make sure we have enough
> > y <- x[(x > -1.5) & (x < 1.5)][1:500]  #
> keep 500 0f them
> > hist(y)
> >
> 
> On Thu, Jul 24, 2008 at 7:35 PM, dxc13
> <dxc13 at health.state.ny.us> wrote:
> >
> > useR's,
> >
> > I want to randomly generate 500 numbers from the
> standard normal
> > distribution, i.e. N(0,1), but I only want them to be
> generated in the range
> > -1.5 to 1.5.  Does anyone have a simple way to do
> this?
> >
> > Thanks,
> >
> > dxc13
> > --
> > View this message in context:
> http://www.nabble.com/simple-random-number-generation-tp18642611p18642611.html
> > Sent from the R help mailing list archive at
> Nabble.com.
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained,
> reproducible code.
> >
> 
> 
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem you are trying to solve?
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.



More information about the R-help mailing list