bugGNU Octave - Bugs: bug #57564, Implementation of rng


bug #57564: Implementation of rng

Submitted by:  Guillaume <gyom>
Submitted on:  Thu 09 Jan 2020 02:43:27 PM UTC  
Category:  Octave Function Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

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


( Jump to the original submission)

Wed 19 Feb 2020 04:12:54 PM UTC, comment #6: 

Guillaume, I checked in your rng.m file, added an entry for it in the manual and NEWS file, and made a few style fixes:


John W. Eaton <jwe>
Project Administrator
Wed 19 Feb 2020 12:43:43 PM UTC, comment #5: 

I would like to ask whether the priority of this report could be moved from "low" to "normal". In recent versions of Matlab, rng() is the only documented function to control random number generators so it gets used more and more and I would argue that random number generation is a very core feature of a language for numerical computations.
I understand more substantial work has to be done in Octave to switch to a single (Mersenne Twister) generator feeding both rand and randn but this can be hidden away from the higher level implementation of rng().

Guillaume <gyom>
Fri 10 Jan 2020 11:33:39 AM UTC, comment #4: 
Guillaume <gyom>
Thu 09 Jan 2020 04:33:21 PM UTC, comment #3: 

Setting group, priority, and severity to be consistent with other missing functions.

John W. Eaton <jwe>
Project Administrator
Thu 09 Jan 2020 03:10:50 PM UTC, comment #2: 

The attached file had an UTF-8 encoding issue, re-attaching.

(file #48188)

Guillaume <gyom>
Thu 09 Jan 2020 03:03:33 PM UTC, comment #1: 
  • meaning of seed 0 in Matlab:


  • numpy can generate the same sequence of numbers for rand than Matlab:

so the same could be achieved with Octave. For randn, Matlab seems to be using one or more rand values, which means that it is likely implementing the Ziggurat algorithm (and not the Marsaglia polar method or the Box–Muller transform).

Guillaume <gyom>
Thu 09 Jan 2020 02:43:27 PM UTC, original submission:  

Matlab has a "rng" function to set and query the state of the random number generator:
This is the recommended syntax. The use of rand('state',...) is discouraged and not documented any more:

I attach a possible implementation for Octave. Currently, Octave has a separate generator for rand and randn so rng stores both states: if and when Octave evolves to use a single generator, the rng function can be updated internally without any visible change from the outside. This means that, in my eye, rng can be considered for inclusion in Octave now even if some work is still to take place in rand/randn.

Guillaume <gyom>


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

Attach Files:

Attached Files
file #48188:  rng.m added by gyom (9KiB - text/x-matlab)
file #48187:  rng.m added by gyom (9KiB - text/x-matlab)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by gyom (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 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-02-21 rik5 StatusReady For Test => Fixed
        Open/ClosedOpen => Closed
    2020-02-19 jwe StatusNone => Ready For Test
    2020-01-09 jwe Severity3 - Normal => 1 - Wish
        Priority5 - Normal => 3 - Low
        Item GroupMatlab Compatibility => Feature Request
    2020-01-09 gyom Attached File- => Added rng.m, #48188
    2020-01-09 gyom Attached File- => Added rng.m, #48187

    Back to the top

    Powered by Savane 3.5