The goal of rngex is to show example random number generation with RcppArmadillo.
You just call the function ranmat
with an integer (n
) and it will
return a random n
x n
matrix. The random values are generated using
RcppArmadillo
.
This is a basic example which shows you how to solve a common problem:
library(rngex)
ranmat(4)
#> $x1
#> [,1] [,2] [,3] [,4]
#> [1,] -2.5882354 0.61602598 0.7841986 0.3268752
#> [2,] 1.4694150 1.94900003 0.5154282 -0.6456358
#> [3,] -0.6051138 -0.94407145 1.0451265 1.5294657
#> [4,] -0.1772512 0.02058098 1.4730661 0.6430811
#>
#> $x2
#> [,1] [,2] [,3] [,4]
#> [1,] -0.50911326 0.6980069 -1.0223692 -0.1246920
#> [2,] 0.66969247 0.2732463 -0.4238590 -1.4621248
#> [3,] 0.08776353 -1.6461928 -0.4541713 -0.5417028
#> [4,] 0.23218313 1.3069803 0.3134058 -0.8457032
ranmat(4)
#> $x1
#> [,1] [,2] [,3] [,4]
#> [1,] -0.60880220 -0.4164090 -0.9771395 1.3965627
#> [2,] 0.52337851 -0.4408878 0.2544416 -0.9794632
#> [3,] 0.06563707 -1.6415752 0.1644328 -1.5639204
#> [4,] -0.31514743 -0.8388426 1.1522672 0.4709026
#>
#> $x2
#> [,1] [,2] [,3] [,4]
#> [1,] 0.98532450 0.9634365 1.6235921 -0.6059924
#> [2,] 0.13029231 -0.3022228 0.3339841 1.2855982
#> [3,] -0.09680805 -0.1244348 -0.4656384 0.7849701
#> [4,] 0.48099888 0.2475045 1.6757931 0.2059066
ranmat(4)
#> $x1
#> [,1] [,2] [,3] [,4]
#> [1,] 0.14876331 0.0940753 0.3453186 -0.79200562
#> [2,] -0.94919710 -2.6087662 -0.9298771 1.56811754
#> [3,] -0.04482623 -0.5129397 -2.2642925 -1.26659067
#> [4,] -0.60509805 -0.6343624 1.1051631 0.03498886
#>
#> $x2
#> [,1] [,2] [,3] [,4]
#> [1,] -0.4491305 0.47001103 1.090928699 -1.4692343
#> [2,] 1.2397566 -0.52447973 0.001580622 0.4249668
#> [3,] 0.8155581 -0.06607009 -1.598329422 -0.1586856
#> [4,] 0.4581683 1.06425340 1.196455990 0.1754057
set.seed(33212)
ranmat(4)
#> $x1
#> [,1] [,2] [,3] [,4]
#> [1,] -0.5718445 1.5874945 0.07825246 -0.02052529
#> [2,] -1.5024390 1.0639790 1.15692404 0.55064120
#> [3,] 0.7389139 0.8592115 -0.13330708 -1.53026580
#> [4,] -1.0998077 -0.2625793 1.91229562 1.23546658
#>
#> $x2
#> [,1] [,2] [,3] [,4]
#> [1,] -0.4332072 0.63229391 2.2094178 -0.004516447
#> [2,] -0.7107103 -0.65996375 -1.1529542 0.391411182
#> [3,] -1.0528802 -0.62888797 -0.4536871 0.014238639
#> [4,] -1.6975019 -0.03377842 0.1867342 -0.604315404
set.seed(33212)
ranmat(4)
#> $x1
#> [,1] [,2] [,3] [,4]
#> [1,] -0.5718445 1.5874945 0.07825246 -0.02052529
#> [2,] -1.5024390 1.0639790 1.15692404 0.55064120
#> [3,] 0.7389139 0.8592115 -0.13330708 -1.53026580
#> [4,] -1.0998077 -0.2625793 1.91229562 1.23546658
#>
#> $x2
#> [,1] [,2] [,3] [,4]
#> [1,] -0.4332072 0.63229391 2.2094178 -0.004516447
#> [2,] -0.7107103 -0.65996375 -1.1529542 0.391411182
#> [3,] -1.0528802 -0.62888797 -0.4536871 0.014238639
#> [4,] -1.6975019 -0.03377842 0.1867342 -0.604315404
set.seed(33212)
ranmat(4)
#> $x1
#> [,1] [,2] [,3] [,4]
#> [1,] -0.5718445 1.5874945 0.07825246 -0.02052529
#> [2,] -1.5024390 1.0639790 1.15692404 0.55064120
#> [3,] 0.7389139 0.8592115 -0.13330708 -1.53026580
#> [4,] -1.0998077 -0.2625793 1.91229562 1.23546658
#>
#> $x2
#> [,1] [,2] [,3] [,4]
#> [1,] -0.4332072 0.63229391 2.2094178 -0.004516447
#> [2,] -0.7107103 -0.65996375 -1.1529542 0.391411182
#> [3,] -1.0528802 -0.62888797 -0.4536871 0.014238639
#> [4,] -1.6975019 -0.03377842 0.1867342 -0.604315404