[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 16:26:03 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0 |
Follow-up Comment #4, bug #54619 (project octave):
There is a correct way to generate random integers in a given range, and there
are incorrect ways. The method that I linked is the correct way. Other ways
are incorrect. The bias might be small, but it's there.
GNU's C++ Standard Library does it right also:
const __uctype __uerange = __urange + 1; // __urange can be zero
const __uctype __scaling = __urngrange / __uerange;
const __uctype __past = __uerange * __scaling;
do
__ret = __uctype(__urng()) - __urngmin;
while (__ret >= __past);
__ret /= __scaling;
No serious scientific software would use the method used by Octave. This is
why I'm reporting it as a bug. Take it or leave it.
Note that random floating-point numbers are totally different from random
integers, and should not be used as a comparison. And they should not be used
as a basis either.
This "large project" is just throwing away randmtzig.cc and replacing that
with stuff from the Standard Library
<https://en.cppreference.com/w/cpp/header/random>. Random number generation is
complicated enough that one should not attempt to reinvent the wheel.
_______________________________________________________
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, 2018/09/06
- [Octave-bug-tracker] [bug #54619] randi() is biased, Rik, 2018/09/06
- [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, 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
- [Octave-bug-tracker] [bug #54619] randi() is biased, Juan Pablo Carbajal, 2018/09/07
- [Octave-bug-tracker] [bug #54619] randi() is biased, Philip Nienhuis, 2018/09/08