[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #54619] randi() is biased
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #54619] randi() is biased |
Date: |
Thu, 6 Sep 2018 12:15:07 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0 |
Follow-up Comment #2, bug #54619 (project octave):
This has nothing to do with the C `rand`. Octave's `randi` is an M-file, you
can type `edit randi` to see it. It uses Octave's `rand`. Line 106:
ri = imin + floor ( (imax-imin+1)*rand (varargin{:}) );
`rand` uses the Mersenne Twister algorithm, which outputs a 64-bit integer,
cast to a double. Even if this cast is done correctly, leading to a perfectly
uniform distribution of values, this double float value doesn't sample integer
values equidistantly, and the output range likely doesn't divide the input
range evenly either. Thus, the division + floor in `randi` will lead to a bias
in the output distribution.
In short, a correct `randi` is implemented using the integer output of the
Mersenne Twister, and using the rejection scheme as shown in the linked Stack
Overflow answer.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?54619>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #54619] randi() is biased, anonymous, 2018/09/04
- [Octave-bug-tracker] [bug #54619] randi() is biased, Rik, 2018/09/05
- [Octave-bug-tracker] [bug #54619] randi() is biased,
anonymous <=
- [Octave-bug-tracker] [bug #54619] randi() is biased, Rik, 2018/09/06
- [Octave-bug-tracker] [bug #54619] randi() is biased, anonymous, 2018/09/06
- [Octave-bug-tracker] [bug #54619] randi() is biased, Rik, 2018/09/06
- [Octave-bug-tracker] [bug #54619] randi() is biased, Juan Pablo Carbajal, 2018/09/06
- [Octave-bug-tracker] [bug #54619] randi() is biased, Michael Godfrey, 2018/09/06
- [Octave-bug-tracker] [bug #54619] randi() is biased, Michael Godfrey, 2018/09/07
- [Octave-bug-tracker] [bug #54619] randi() is biased, Rik, 2018/09/07
- [Octave-bug-tracker] [bug #54619] randi() is biased, Michael Godfrey, 2018/09/07
- [Octave-bug-tracker] [bug #54619] randi() is biased, anonymous, 2018/09/07
- [Octave-bug-tracker] [bug #54619] randi() is biased, Michael Leitner, 2018/09/07