bugGNU Octave - Bugs: bug #45879, randi out of range with integer...

 
 

bug #45879: randi out of range with integer arguments

Submitter:  Ceral Paquet <octavebugs>
Submitted:  Sat 05 Sep 2015 01:18:57 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  siko1056
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 08 Sep 2015 08:44:46 AM UTC, comment #6: 

The issues regarding different input data types should be fixed by the changeset now.

http://hg.savannah.gnu.org/hgweb/octave/rev/f515bac7c7c1

Update randi.m to this version:

http://hg.savannah.gnu.org/hgweb/octave/file/f515bac7c7c1/scripts/general/randi.m

Any feedback is welcome!

Kai Torben Ohlhus <siko1056>
Group Member
Mon 07 Sep 2015 10:16:39 PM UTC, comment #5: 

I confirm this function was never intended for integer input "imax". The fix from https://savannah.gnu.org/bugs/?45879#comment1 works for me too, but I think this function needs a small makeover, see https://savannah.gnu.org/bugs/?45879#comment3 .

Kai Torben Ohlhus <siko1056>
Group Member
Mon 07 Sep 2015 07:50:49 PM UTC, comment #4: 

The fix in comment #1 fix this

Avinoam Kalma <avinoam>
Group Member
Mon 07 Sep 2015 05:28:30 PM UTC, comment #3: 

Another little bug.

class(randi(int32(10),'double'))
ans = int32

In Matlab the result is ans = double.








Ceral Paquet <octavebugs>
Sat 05 Sep 2015 10:24:30 PM UTC, comment #2: 

I think random numbers are incredibly tricky to get right :)

http://akbar.marlboro.edu/~mahoney/courses/Fall01/computation/NumeralRecipesCpdf/c7-1.pdf




Ceral Paquet <octavebugs>
Sat 05 Sep 2015 09:08:14 PM UTC, comment #1: 


The problem is in the line


ri = imin + floor ( (imax-imin+1)*rand (varargin{:}) );


in randi. Changing to


  ri = imin + floor ( double((imax-imin+1))*rand (varargin{:}) );


will solve the problem.
what do you think?

Avinoam Kalma <avinoam>
Group Member
Sat 05 Sep 2015 01:18:57 PM UTC, original submission:  


>> max(randi(int64(100),1000,1))

ans = 101

Same result with int8, 16, 32 and unsigned.

Ceral Paquet <octavebugs>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by avinoam (Posted a comment)
  • -email is unavailable- added by octavebugs (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-09-08 siko1056 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2015-09-08 siko1056 StatusConfirmed In Progress
    2015-09-07 siko1056 StatusNone Confirmed
        Assigned toNone siko1056
        Release4.0.0 dev

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code