Fri 09 Jul 2010 01:37:30 PM UTC, original submission:
in octave interpreter "rand" gives uniform random numbers while randn gives gaussian random numbers.
Indeed, calling
--rand ("state", [1:625]); rand
gives uniform numbers.
However, after calling within the interpreter a dld function that changes the mode of the random number generator like below
--dummyfunc
subsequent calls to
--rand ("state", [1:625]); rand
produces gaussian and not anymore uniform random numbers.
--This bug does not depend on the seed of the generator, i.e. replace [1:625] by anything integer.
Fixing is easy as one simply need to reset the mode of the generator before exiting the dld function.
However, I think that a dld function should not be able to "swap" the rand and the randn functions in octave interpreter.
dld function compiled with mkoctfile
#include <octave/oct.h>
#include <octave/oct-rand.h>
DEFUN_DLD (dummyfunc,args,nargout,"")
{
octave_rand::distribution("normal"); // put octave random generator to gaussian mode
// do something
//octave_rand::distribution("uniform"); // put the generator back to uniform mode for correct behavior
return octave_value_list();
//----------------------------------------------------------//
}
|