[R] Generate quasi-random positive numbers

Martyn Byng martyn.byng at nag.co.uk
Tue Aug 5 13:24:14 CEST 2014


As a slight aside, did you mean pseudo-random or quasi-random?


runif gives a sequence of pseudo-random numbers, for quasi-random numbers you will need something else, for example the Sobol generator from http://cran.r-project.org/web/packages/randtoolbox/index.html.


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Frederico Mestre
Sent: 05 August 2014 11:28
To: r-help at r-project.org
Subject: [R] Generate quasi-random positive numbers

Hello all:

Is it possible to generate quasi-random positive numbers, given a standard deviation and mean? I need all positive values to have the same probability of selection (uniform distribution). Something like:

runif(10, min = 0, max = 100)

This way I'm generating random positive numbers from a uniform distribution. However, using runif I can't previously select SD and mean (as in rnorm).

Alternatively, I'm able to generate a list of quasi-random numbers given a SD and a mean.

b <- (sqrt(SD^2*12)+(MEAN*2))/2
a <- (MEAN*2) - b
x1 <- runif(N,a,b)

However, negative values might be included, since "a" can assume a negative value.

Any help?


	[[alternative HTML version deleted]]

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

This e-mail has been scanned for all viruses by Star.\ _...{{dropped:3}}

More information about the R-help mailing list