rndn#
Purpose#
Computes normally distributed pseudo-random numbers with a choice of underlying random number generator.
Format#
- y = rndn(r, c)#
- { y, newstate } = rndn(r, c, state)
- Parameters:
r (scalar) – row dimension.
c (scalar) – column dimension.
state (scalar or opaque vector) –
Optional argument.
scalar case
state = starting seed value only. If -1, GAUSS computes the starting seed based on the system clock.
opaque vector case
state = the state vector returned from a previous call to one of the
rnd
random number functions.
- Returns:
y (RxC matrix) – standard normal random numbers.
newstate (Opaque vector) – the updated state.
Examples#
Example 1#
//Create a 100 by 1 vector of standard normal numbers
my_var = rndn(100, 1);
Example 2#
This example simulates the linear model: \(y = \alpha + \beta_1*X + \epsilon\)
num_obs = 100;
alpha = 2.5;
beta_1 = 0.8;
// Simulate error term
err = rndn(num_obs, 1);
// Simulate 'x' variable
x = rndn(num_obs, 1);
// Simulate data generating process
y = alpha + beta_1*x + err;
Example 3#
This example generates two thousand vectors of standard normal random numbers, each with one million elements. The state of the random number generator after each iteration is used as an input to the next generation of random numbers.
state = 13;
n = 2000;
k = 1000000;
// Create vector to hold 'n' submeans
submean = zeros(n, 1);
for i(1, n, 1);
// Create a kx1 vector of random normal numbers,
// using the optional 'state' input
{ y, state } = rndn(k, 1, state);
submean[i] = meanc(y);
endfor;
mean = meanc(submean);
print mean;
Remarks#
r and c will be truncated to integers if necessary.
Technical Notes#
The default generator for
rndn()
is the SFMT Mersenne-Twister 19937. You can specify a different underlying random number generator with the functionrndCreateState()
.The rndseed keyword will create a new state vector (starting point) for
rndn()
. This means you can use rndseed to controlrndn()
. However,rndn()
will not update the rndseed as its internal state changes.For testing and comparison purposes, the function
_rndng10()
will reproduce the results of the functionrndn()
in GAUSS 10 and earlier. In GAUSS 11 an improvement to the normality transformation algorithm was added torndn()
. This can be reproduced with the function_rndn()
. Do not use either of the functions for any purpose other than comparison with previous versions. The currentrndn()
algorithm is a much higher quality random number generator.
See also
Functions rndCreateState()
, rndStateSkip()