Mercurial > octave
diff liboctave/numeric/randmtzig.cc @ 24856:8bb0251fcfde
Use a uint32 state vector for random number generators (bug #50256).
* oct-rand.h: Remove #include "dColVector.h" and replace with #include
"uint32NDArray.h". Replace all instances of ColumnVector with uint32NDArray.
* oct-rand.cc: Replace all instances of ColumnVector with uint32NDArray.
* oct-rand.cc (get_internal_state): Remove use of OCTAVE_LOCAL_BUFFER.
Use s.fortran_vec () to pass pointer to state vector data directly to
oct_get_state().
* oct-rand.cc (set_internal_state): Remove use of OCTAVE_LOCAL_BUFFER.
Use s.data () to pass const pointer to state vector data directly to
oct_set_state().
* oct-rand.cc (double2uint32): Remove obsolete function.
* randmtzig.h (oct_init_by_int): Change prototype to accept const value.
* randmtzig.h (oct_init_by_array): Change prototype to accept const value.
* randmtzig.h (oct_set_state): Change prototype to accept const value.
* randmtzig.cc (oct_init_by_int, oct_init_by_array, oct_set_state): Change
functions to match new prototypes. Declare temporary loop variable
just-in-time.
* randmtzig.cc (oct_get_state, oct_set_state): Use std::copy_n instead of
for loop to simplify code.
* rand.cc (Frand, Frandn, Frande, Frandg, Frandp): Change tolerances for BIST
tests which use the new RNG to be much tighter. Use '_' in large numbers for
readability. Change out-of-range seed testing to match new behavior.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 09 Mar 2018 16:40:12 -0800 |
parents | 194eb4bd202b |
children | b8ce68627441 |
line wrap: on
line diff
--- a/liboctave/numeric/randmtzig.cc Fri Mar 09 17:14:52 2018 -0500 +++ b/liboctave/numeric/randmtzig.cc Fri Mar 09 16:40:12 2018 -0800 @@ -159,6 +159,8 @@ #include <cmath> #include <cstdio> +#include <algorithm> + #include "oct-time.h" #include "randmtzig.h" @@ -189,7 +191,7 @@ /* initializes state[MT_N] with a seed */ void -oct_init_by_int (uint32_t s) +oct_init_by_int (const uint32_t s) { int j; state[0] = s & 0xffffffffUL; @@ -210,7 +212,7 @@ /* init_key is the array for initializing keys */ /* key_length is its length */ void -oct_init_by_array (uint32_t *init_key, int key_length) +oct_init_by_array (const uint32_t *init_key, const int key_length) { int i, j, k; oct_init_by_int (19650218UL); @@ -289,11 +291,9 @@ } void -oct_set_state (uint32_t *save) +oct_set_state (const uint32_t *save) { - int i; - for (i = 0; i < MT_N; i++) - state[i] = save[i]; + std::copy_n (save, MT_N, state); left = save[MT_N]; next = state + (MT_N - left + 1); } @@ -301,9 +301,7 @@ void oct_get_state (uint32_t *save) { - int i; - for (i = 0; i < MT_N; i++) - save[i] = state[i]; + std::copy_n (state, MT_N, save); save[MT_N] = left; }