Random numbers¶
Simple interface¶
Advanced interface¶
-
RngCreate
()¶ -
RngCreate
(seed) -
RngCreate
([seed=seed][, engine=engine][, dist=dist]) -
RngCreate
({seed, engine, dist}) create a pseudo-random generator
RngCreate()
returns a list which is a well-formed RNG object. Its value should be saved in a variable and used to callRng()
andRngSeed()
.Engines:
default
advanced
Distributions:
default
(the same asflat
)flat
(uniform)gauss
(normal)
-
RngSeed
(r, seed)¶ (re)seed pseudo-random number generator
RngSeed()
re-initializes the RNG objectr
with the seed valueseed
. The seed value should be a positive integer.
See also
-
Rng
(r)¶ generate pseudo-random number
Rng(r)()
returns a floating-point random number between 0 and 1 and updates the RNG objectr
. (Currently, the Gaussian option makes a RNG return a complex random number instead of a real random number.)See also
Auxilliary functions¶
-
RandomIntegerMatrix
(rows, cols, from, to)¶ generate a matrix of random integers
This function generates a
rows x cols
matrix of random integers. All entries lie betweenfrom
andto
, including the boundaries, and are uniformly distributed in this interval.- Example
In> PrettyForm( RandomIntegerMatrix(5,5,-2^10,2^10) ) / \ | ( -506 ) ( 749 ) ( -574 ) ( -674 ) ( -106 ) | | | | ( 301 ) ( 151 ) ( -326 ) ( -56 ) ( -277 ) | | | | ( 777 ) ( -761 ) ( -161 ) ( -918 ) ( -417 ) | | | | ( -518 ) ( 127 ) ( 136 ) ( 797 ) ( -406 ) | | | | ( 679 ) ( 854 ) ( -78 ) ( 503 ) ( 772 ) | \ /
See also
-
RandomIntegerVector
(n, from, to)¶ generate a vector of random integers
This function generates a list with
n
random integers. All entries lie betweenfrom
andto
, including the boundaries, and are uniformly distributed in this interval.- Example
In> RandomIntegerVector(4,-3,3) Out> {0,3,2,-2};
See also
-
RandomPoly
(var, deg, coefmin, coefmax)¶ construct a random polynomial
RandomPoly()
generates a random polynomial in the variablevar
, of degreedeg
, with integer coefficients ranging fromcoefmin
tocoefmax
(inclusive). The coefficients are uniformly distributed in this interval, and are independent of each other.- Example
In> RandomPoly(x,3,-10,10) Out> 3*x^3+10*x^2-4*x-6; In> RandomPoly(x,3,-10,10) Out> -2*x^3-8*x^2+8;
See also