rand | R Documentation |
Random float vector/matrix generators. flrunif()
produces uniform
random values. flrnorm()
produces random normal values.
flrand()
will accept an arbitrary generator. See the details section
for more information.
flrunif(m, n, min = 0, max = 1)
flrnorm(m, n, mean = 0, sd = 1)
flrand(generator, m, n, ...)
m , n |
The dimensions of the matrix/vector. |
min , max |
Minimum and maximum values for the uniform generator. |
mean , sd |
Mean and standard deviation values for the normal generator. |
generator |
A generating function, such as |
... |
Additional arguments passed to the generator. For example, if |
For flrunif()
and flrnorm()
, the data is produced without a
double precision copy. That is, it is not (computationally) equivalent to
fl(matrix(runif(...)))
, though the operations are conceptually the
same. For these, To produce a vector instead of a matrix, leave argument
n
blank. Setting n=1
will produce an mx1 matrix.
For flrand()
, the data is generated in double precision in 4KiB
batches and copied over to a pre-allocated vector. This will be slower than
generating all of the data up front and copying it, although it uses far less
memory most of the time. So you can think of flrunif()
and
flrnorm()
as highly optimized versions of flrand()
for uniform
and normal generators specifically.
library(float)
flrunif(10) # length 10 vector
flrunif(10, 1) # 10x1 matrix
flrunif(10, min=10, max=20)
flrand(runif, 10) # conceptually the same as flrunif(10)
mygen = function(n) sample(1:5, n, replace=TRUE)
flrand(mygen, 30)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.