float (version 0.2-3)

rand: Generators

Description

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.

Usage

flrunif(m, n, min = 0, max = 1)

flrnorm(m, n, mean = 0, sd = 1)

flrand(generator, m, n, ...)

Arguments

m, n

The dimensions of the matrix/vector. m must be specified. If n is not, then the return is a 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 rnorm, or even something custom defined.

...

Additional arguments passed to the generator. For example, if runif is passed as generator, then you might additionally pass max=10.

Details

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.

Examples

Run this code
# NOT RUN {
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)

# }

Run the code above in your browser using DataCamp Workspace