[bug #68606] Output distribution of rand is unspecified

<[email protected]>
Newsgroups gmane.comp.gnu.octave.bugs
Message-ID <[email protected]>
Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only notification stream.  Info posted to this mailing list address won't appear in the tracker database where it is most useful.

URL:
  <https://savannah.gnu.org/bugs/?68606>

                 Summary: Output distribution of rand is unspecified
                   Group: GNU Octave
               Submitter: vhihrvvkndet
               Submitted: Mon 10 Aug 2026 06:48:36 PM UTC
                Category: Documentation
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Documentation
                  Status: None
             Assigned to: None
         Originator Name:
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Unlocked
                 Release: 11.3.0
        Operating System: Any
           Fixed Release: None
         Planned Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Mon 10 Aug 2026 06:48:36 PM UTC By: Anonymous
The output distribution of the rand function is not really specified.  The
documentation says:
> Return a scalar, matrix, or N-dimensional array whose elements are random
> numbers uniformly distributed on the interval (0, 1).
This sounds like a continuous distribution, but the function returns floating
point numbers which are a finite set, so it's actually a discrete
distribution.  The set of possible outcomes is not specified though.  It's
certainly not uniform over all the floating point numbers in (0, 1).  Some
cursory testing suggests that rand(M, N, 'single') yields only integer
multiples of eps(single(0.9)) in the interval (0, 1), and it appears that
almost all or perhaps all such values can be produced.  Similarly, rand(M, N)
seems to yield only integer multiples of eps(0.9).  I did not try to assess
uniformity in detail.

I think the documentation for rand should precisely specify the output
distribution (or at least what it would be if the underlying source of
randomness is perfect).  It might be undesired to commit to a particular
distribution, but that shouldn't prevent specifying what is currently used.

For what it's worth, I find the current behavior fairly unintuitive.  I'd
naively expect something like "select a real number uniformly at random from
the interval (0, 1), then return the largest floating point value less than
it", but the current behavior is a very poor approximation of that in some
regards.  For instance, I'd expect `rand('single') < 2^-28` to be true with
probability very near 2^-28, but it seems the probability is actually zero.








    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?68606>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCanodCAAKCRCqLAuaBUf3
TtxzAP4loEMPz/UYYFQh5Q+JMhBngED6EPt0jlwSgePTrvdbfgD/eUtNJdnXQ04N
CmgRWUnB9w8mNj9a5+ioqlYiHNSILgM=
=BnIA
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.