http://qs321.pair.com?node_id=1184450


in reply to inclusive rand

A bit of probability theory: if X has the Uniform(0,1) distribution, the support (range) is [0,1]. If the support is actually [0,1), then the distribution is actually Uniform(0, 1-epsilon) for some small epsilon. In this case, if you knew what epsilon is, you could scale by the width of the support to get Y = X/(1 - epsilon - 0) = X/(1 - epsilon) and Y would have true Uniform(0,1) distribution.

As others have pointed out, there are a number of factors involved and epsilon likely isn't just the machine epsilon or unit roundoff. Besides, even if it were, see pryrt's reply Re^6: inclusive rand. The figure in question is too small; on normal floating point hardware, dividing by 1-epsilon would be no different from dividing by 1.

Replies are listed 'Best First'.
Re^2: inclusive rand
by Lotus1 (Vicar) on Mar 13, 2017 at 18:34 UTC

    This finds the smallest difference between any two random values.

    use strict; use warnings; use List::MoreUtils qw(uniq); use List::Util qw(min); my @samples = sort { $a <=> $b } uniq map {rand} 1..3000; print scalar @samples, " unique samples.\n"; print "The minimum difference is ", min map { $samples[$_] - $samples[ +$_-1] } 1..$#samples; __END__ 2861 unique samples. The minimum difference is 3.0517578125e-005