Generating Random Numbers Model: DEMRND
In cases where you are modeling under uncertainty, it is useful to have a random number generator to help simulate a situation. LINGO supports the @RAND function, which can be used to generate sequences of pseudo random numbers with uniform distribution between 0 and 1. By using the same seed value, you can recreate a series of numbers. In this example, we generate 15 random numbers, and then use them with the @PSN and @PTD functions to generate observations from both the unit Normal and T distributions.
MODEL:
! Generate a series of Normal and T distributed
random variables ;
SETS:
SERIES/1..15/: U, ZNORM, ZT;
ENDSETS
! First uniform is arbitrary;
U( 1) = @RAND( .1234);
! Generate the rest recursively;
@FOR( SERIES( I)| I #GT# 1:
U( I) = @RAND( U( I - 1))
);
! Generate some...;
@FOR( SERIES( I):
! Normal deviates...;
@PSN( ZNORM( I)) = U( I);
! and t deviates(2 degrees of freedom);
@PTD( 2, ZT( I)) = U( I);
! ZNORM and ZT may take on negative values;
@FREE( ZNORM( I)); @FREE( ZT( I));
);
END
Model: DEMRND