This function wraps a call to the standard Octave
function rand
, which is redefined by
RcppOctave
to call the R base function
runif
. This enables to exactly
reproduce stochastic computations in R and Octave,
without changing the original Octave/Matlab code.
o_runif(n, p = n)
n
)a numeric vector or a matrix
Since calling o_runif
or
runif
is equivalent, this function
may not be really useful for the end user, and is defined
for testing purposes essentially. One possible advantage
over plain runif
however, is that it
can generate random matrices, instead of only vectors
(see examples).
Because the RNG of R is called used, seeding computations
is achieved by a standard call to set.seed
.
RcppOctave
defines a set of functions like
rand
that shadow Octave built-in functions. These
functions are defined in the Octave module
Rrng.oct
that is stored in the package
modules/ sub-directory. See
Octave.info('modules')
to see this directory's
full path.
USAGE: U = rand( n [, k]) Generates uniform random variates as R function 'runif' -- using the current RNG from R. Possible calls: rand(n, k) returns a n*k matrix with uncorrelated U(0, 1) deviates drawn in columns rand(n) returns a n*n matrix with uncorrelated U(0, 1) deviates drawn in columns NOTE: This function substitutes Octave original function in calls from RcppOctave
[Generated from Octave-3.6.4 on 2014-05-21 11:08:21 ]
## Don't show:
# roxygen generated flag
options(R_CHECK_RUNNING_EXAMPLES_=TRUE)
## End Don't show
# Draw random uniform values (in vector form)
set.seed(123)
o_runif(1)
## [1] 0.2876
o_runif(1, 10)
## [1] 0.78831 0.40898 0.88302 0.94047 0.04556 0.52811 0.89242 0.55144
## [9] 0.45661 0.95683
# The result is identical as calling runif
set.seed(123)
runif(1)
## [1] 0.2876
runif(10)
## [1] 0.78831 0.40898 0.88302 0.94047 0.04556 0.52811 0.89242 0.55144
## [9] 0.45661 0.95683
# Draw random uniform values (in matrix form)
set.seed(123)
o_runif(2)
## [,1] [,2]
## [1,] 0.2876 0.409
## [2,] 0.7883 0.883
o_runif(2, 5)
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.94047 0.5281 0.5514 0.9568 0.6776
## [2,] 0.04556 0.8924 0.4566 0.4533 0.5726