Armadillo random number generation on macOS with GCC
Currently seeing issues with random number generation in Armadillo when compiling natively on macOS with GCC. This issue is primarily to document this, as it is presumably an issue somewhere upstream. Minimal example below.
Contents of arma_test.c++
:
#include <iostream>
#include <armadillo>
int main(int, char**)
{
arma::arma_rng::set_seed(42);
std::cout << arma::randn<arma::fvec>(5u) << std::endl;
return 0;
}
Output using different compilers:
$ g++ --version
g++ (MacPorts gcc10 10.2.0_4) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ sudo port install armadillo +gcc10
...
$ g++ -std=c++14 -Wall -Wextra \
> -I/opt/local/include -L/opt/local/lib -larmadillo \
> arma_test.c++ -o arma_test && ./arma_test
0
0
0
0
0
$ clang++ --version
clang version 10.0.1
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-10/bin
$ sudo port install armadillo +clang10
...
$ clang++ -std=c++14 -Wall -Wextra \
> -I/opt/local/include -L/opt/local/lib -larmadillo \
> arma_test.c++ -o arma_test && ./arma_test
...
1.2938
0.7050
0.3980
-0.5741
1.1186
Edited by Sam Harrison