Yes, that is better in that it includes the boundaries, but getting exactly zero is half the probability of any other outcome, still... (ok half of 0.00000001 is also pretty damn small)

I guess what I am asking is if there is hardcoded function random(a,b) that returns a random value x between [a,b] using a flat PDF?

Posts: 47
Joined: 2008-04-23
Location: United States

A slightly longer reply than John's is that if you really need to distinguish an inclusive vs. exclusive border in double precision floating point arithmetic (which is what returned by enoise)

a: you're probably doing something wrong
b: you will run into other precision and granularity problems not just at the borders

Note that
print enoise(1) has about the same odds of showing you -1 as 1 on the history, despite the different endpoint treatment, and each of -1 or 1 has about half the probability of appearing as any other multiple of 1e-6. That's not built into enoise...it's a function of print defaulting to 6 decimal digits of precision and rounding to the nearest 6 digit value. The real value returned by your expression actually has a granularity of about 1e-17, so the statistical bias of 1 vs. -1 will be about 1e-11.

Your original solution is on the right track, but you came up with the symmetric, exclusive version: 0 and 1 not included when rounding to 1e-6. If you're really trying to get a distribution which after rounding to the nearest 1e-6, could give you 0 or 1 inclusive with equal probability to any other multiple of 1e-6 then I think the answer is

Thanks for the replies, I was really just worried I was doing it the hard way (or wrong) and am aware that the "unevenness" is vanishingly small, but it is interesting to see the finer details of how this works on a machine level.

Joined: 2009-01-06

Location: Switzerland

i guess this should do:

Joined: 2012-04-18

Location: Denmark

Yes, that is better in that it includes the boundaries, but getting exactly zero is half the probability of any other outcome, still... (ok half of 0.00000001 is also pretty damn small)

I guess what I am asking is if there is hardcoded function random(a,b) that returns a random value x between [a,b] using a flat PDF?

Joined: 2007-06-29

Location: United States

daggazwrote:And the answer would be no.

John Weeks

WaveMetrics, Inc.

support@wavemetrics.com

Joined: 2007-06-29

Location: United States

Try this:

Note that the actual probability of getting a random value that is exactly 'a' is vanishingly small.

A.G.

WaveMetrics, Inc.

Joined: 2008-04-23

Location: United States

A slightly longer reply than John's is that if you really need to distinguish an inclusive vs. exclusive border in double precision floating point arithmetic (which is what returned by enoise)

a: you're probably doing something wrong

b: you will run into other precision and granularity problems not just at the borders

Note that

print enoise(1) has about the same odds of showing you -1 as 1 on the history, despite the different endpoint treatment, and each of -1 or 1 has about half the probability of appearing as any other multiple of 1e-6. That's not built into enoise...it's a function of print defaulting to 6 decimal digits of precision and rounding to the nearest 6 digit value. The real value returned by your expression actually has a granularity of about 1e-17, so the statistical bias of 1 vs. -1 will be about 1e-11.

Your original solution is on the right track, but you came up with the symmetric, exclusive version: 0 and 1 not included when rounding to 1e-6. If you're really trying to get a distribution which

after rounding to the nearest 1e-6, could give you 0 or 1 inclusive with equal probability to any other multiple of 1e-6 then I think the answer israndom_x = enoise(0.5 + 5e-7) + 0.5

Joined: 2012-04-18

Location: Denmark

Thanks for the replies, I was really just worried I was doing it the hard way (or wrong) and am aware that the "unevenness" is vanishingly small, but it is interesting to see the finer details of how this works on a machine level.