Skip to content
Paco Zamora Martinez edited this page Jun 14, 2015 · 5 revisions

Introduction

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.

Methods of random class

random contains the following methods:

Constructor

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.

rand

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.

randExc

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.

randDblExc

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.

randInt

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].

shuffle

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.

choose

number = obj:choose(size)

$eturns a random element for an array of the given size. It is equivalent to obj:randInt(1,size).

randNorm

number = obj:randNorm(mean,variance)

Returns a random number sampled from a Gaussian with the given mean and variance parameters.

seed

obj:seed(number)

Modifies the seed, see the constructor.

obj:seed(table)

Modifies the seed, see the constructor.

clone

another = obj:clone()

Returns a deep copy of the caller object.

Clone this wiki locally