-
Notifications
You must be signed in to change notification settings - Fork 12
27 random
Package random
could be loaded via the standalone binary, or in Lua with
require("aprilann.random)
.
The random
class is useful to generate pseudo-random numbers, and is widely
used by ANN components and other classes of APRIL-ANN. It is based on
Mersenne Twister, basically it
is a binding of the original C++ code of Mersenne Twister.
random
contains the following methods:
obj = random( [seed] )
A constructor of the object. The parameter is optional, if not given, it is taken from the current time of the machine. If given, it could be:
-
a seed
number
for the initialization of the random generator; -
a
table
with seeds for the initialization of the random generator.
number = obj:rand( [number] )
Returns a double random number in the interval [0,n]
, being n
the given
parameter. If not given any parameter, by default n=1
.
number = obj:randExc( [number] )
Returns a double random number in the interval
[0,n)
, being n
the given parameter. If not given any parameter, by default n=1
.
number = obj:randDblExc( [number] )
Returns a double random number in the interval (0,n)
, being n
the given
parameter. If not given any parameter, by default n=1
.
number = obj:randInt( [x, [ y ] ] )
Returns an integer random number in the
interval [x,y]
. If only one argument is given, then the interval will be
[0,x]
. If zero argument are given, the interval will be [0,2^32-1]
.
table = obj:shuffle(N)
Returns a table with size N
, which is a permutation of the indices of an
N-sized array.
table = obj:shuffle(table)
Returns a random permutation of the given table array.
number = obj:choose(size)
$eturns a random element for an array of the given size
. It is equivalent to
obj:randInt(1,size)
.
number = obj:randNorm(mean,variance)
Returns a random number sampled from a Gaussian with the given mean
and
variance
parameters.
obj:seed(number)
Modifies the seed, see the constructor.
obj:seed(table)
Modifies the seed, see the constructor.
another = obj:clone()
Returns a deep copy of the caller object.