static PyObject * random_get_seeds(PyObject *self, PyObject *args) { long seed1, seed2; if (!PyArg_ParseTuple(args, "")) return NULL; getsd(&seed1, &seed2); return Py_BuildValue("ll", seed1, seed2); }
void gfmUserDefd_InitializeChain(void) { long temp1, temp2; if(gUseSameSeeds == 1) { setall((long)gC->Seed1, (long)gC->Seed2); } else { getsd(&temp1, &temp2); gC->Seed1 = temp1; gC->Seed2 = temp2; } InitializeChain(gC); }
void apprcirc(long *n, double *Hurst, double *L, int *cum, long *seed1, long *seed2, double *output) { /* function that generates a fractional Brownian motion or fractional */ /* Gaussian noise sample using the approximate circulant method. */ /* Input: *n determines the sample size N by N=2^(*n) */ /* *Hurst the Hurst parameter of the trace */ /* *L the sample is generated on [0,L] */ /* *cum = 0: fractional Gaussian noise is produced */ /* = 1: fractional Brownian motion is produced */ /* *seed1 seed1 for the random generator */ /* *seed2 seed2 for the random generator */ /* Output: *seed1 new seed1 of the random generator */ /* *seed2 new seed2 of the random generator */ /* *output the resulting sample is stored in this array */ long i, N, halfN, generator; double scaling, H; double *pow_spec; double aux; complex *a; halfN = pow(2,*n); H = *Hurst; N = 2*halfN; /* set random generator and seeds */ snorm(); generator = 1; gscgn(1, &generator); setall(*seed1,*seed2); /* allocate memory */ pow_spec = (double*) malloc((halfN+1)*sizeof(double)); /* approximate spectral density */ FGN_spectrum(pow_spec,halfN,H); a = malloc(N*sizeof(complex)); a[0].re = sqrt(2*(pow(N,2*H)-pow(N-1,2*H)))*snorm(); a[0].im = 0.; a[halfN].re = sqrt(2*pow_spec[halfN])*snorm(); a[halfN].im = 0.; for(i=1; i<halfN; i++) { aux = sqrt(pow_spec[i]); a[i].re = aux*snorm(); a[i].im = aux*snorm(); } for(i=halfN+1; i<N; i++) { a[i].re = a[N-i].re; a[i].im = -a[N-i].im; } /* real part of Fourier transform of a_re + i a_im gives sample path */ fft(N,a,1,1.0); /* rescale to obtain a sample of size 2^(*n) on [0,L] */ scaling = pow(*L/halfN,H)/sqrt(2*N); for(i=0;i<halfN;i++) { output[i] = scaling*(a[i].re); if (*cum && i>0) { output[i] += output[i-1]; } } /* store the new random seeds and free memory */ getsd(seed1,seed2); free(pow_spec); free(a); }