From 1e34a426db5f27a5fd9e11d0d75166dd740a9a62 Mon Sep 17 00:00:00 2001 From: Yasunori Watanabe Date: Mon, 27 Apr 2026 15:38:19 +0900 Subject: [PATCH] fix: remove manual GetRNGstate/PutRNGstate to prevent RNG double management --- src/miaaft_core.cpp | 2 -- src/xi_core.cpp | 4 ---- 2 files changed, 6 deletions(-) diff --git a/src/miaaft_core.cpp b/src/miaaft_core.cpp index b54af97..059b62d 100644 --- a/src/miaaft_core.cpp +++ b/src/miaaft_core.cpp @@ -14,7 +14,6 @@ double xi_coefficient(arma::vec x, arma::vec y); // so that the inverse FFT results in a real-valued time series. vec generate_shared_random_phases(int n) { vec phases(n, fill::zeros); - GetRNGstate(); // Pull RNG state from R // Generate random phases for positive frequencies for(int i = 1; i <= (n - 1) / 2; i++) { @@ -28,7 +27,6 @@ vec generate_shared_random_phases(int n) { phases(n / 2) = 0; } - PutRNGstate(); // Return RNG state to R return phases; } diff --git a/src/xi_core.cpp b/src/xi_core.cpp index abb71e5..8eb1b60 100644 --- a/src/xi_core.cpp +++ b/src/xi_core.cpp @@ -10,7 +10,6 @@ using namespace arma; // Shuffles indices using R's random number generator to ensure // exact reproducibility with set.seed() from the R environment. void shuffle_indices_with_r_seed(uvec& idx) { - GetRNGstate(); // Pull RNG state from R int n = idx.n_elem; for (int i = n - 1; i > 0; i--) { int j = floor(R::runif(0, 1) * (i + 1)); @@ -18,7 +17,6 @@ void shuffle_indices_with_r_seed(uvec& idx) { idx[i] = idx[j]; idx[j] = tmp; } - PutRNGstate(); // Return RNG state to R } // ============================================================ @@ -99,7 +97,6 @@ arma::mat generate_iaaft_surrogates(arma::vec x, int n_surr, int max_iter = 100) vec amplitudes = abs(X_fft); vec x_sorted = sort(x); - GetRNGstate(); for(int s = 0; s < n_surr; s++) { vec surr = shuffle(x); @@ -125,7 +122,6 @@ arma::mat generate_iaaft_surrogates(arma::vec x, int n_surr, int max_iter = 100) surrogates.col(s) = surr; } - PutRNGstate(); return surrogates; }