bugGNU Octave - Bugs: bug #30399, DLD can change rand distribution...


bug #30399: DLD can change rand distribution in octave interpreter

Submitted by:  julien javaloyes <javaloye>
Submitted on:  Fri 09 Jul 2010 01:37:30 PM UTC  
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  Jaroslav Hajek <highegg>
Originator Name:  julien Open/Closed:  Closed
Release:  3.2.3 Operating System:  GNU/Linux

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Mon 12 Jul 2010 01:32:39 PM UTC, comment #3: 

rand("poisson") isn't supposed to work, but it perhaps makes sense to support a syntax like rand("normal", m, n). I'd say forget it and just close this bug report as this is not supportted in matlab and your change addresses the original bug.


David Bateman <dbateman>
Project Member
Mon 12 Jul 2010 09:13:29 AM UTC, comment #2: 

Something I wanted done long ago is allow unwind_protect register funcs with const ref arguments, so it's done. With that, neither the global variable nor the wrapper are needed any more:

A final thing to notice is that do_rand somehow attempts to react to things like rand ("poisson").

Is that supposed to work? And how?

Jaroslav Hajek <highegg>In charge of this item.
Fri 09 Jul 2010 08:43:48 PM UTC, comment #1: 

When you stick your hand into the innards of a machine to try and improve its performance your responsible for the case that the machine chews your hand up and spits it back at you. This is pretty much what you are doing with an oct-file in Octave or even a mex-file in matlab. So you shouldn't be surprised that something like this is possible. Its the price of the freedom to write for Octave in C++

That being said I'd say we should probably be consistent in our treatment of the random distribution and reset the distribution in the Frand function, like it is in Frandn, etc, and something like the attached should probably be applied.

Any comments from others before I apply it


(file #20932)

David Bateman <dbateman>
Project Member
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


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();       

julien javaloyes <javaloye>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #20932:  patch added by dbateman (1KiB - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by highegg (Posted a comment)
  • -email is unavailable- added by dbateman (Updated the item)
  • -email is unavailable- added by javaloye (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-07-12 dbateman StatusIn Progress => Fixed
        Assigned todbateman => highegg
        Open/ClosedOpen => Closed
    2010-07-09 dbateman Attached File- => Added patch, #20932
        StatusNone => In Progress
        Assigned toNone => dbateman

    Back to the top

    Powered by Savane 3.5