how can i pick a real number at random though?

i tried Math.random(), but that gave a rational number. i'm very lucky i guess?

You can't actually pick real numbers at random. You especially can't do it on a computer, since all numbers representable in a finite number of digits or bits are rational.

Careful -- that statement is half true.

It's true that no matter what symbolic representation format you choose (binary or otherwise) it will never be able to encode all irrational numbers, because there are uncountably many of them.

But it's certainly false that computers can only represent rational numbers. Sure, there are certain conventional formats that can only represent rational numbers (e.g. IEEE-754 floating point) but it's easy to come up with other formats that can represent irrationals as well. For instance, the Unicode string "√5" is representable as 4 UTF-8 bytes and unambiguously denotes a particular irrational.

I was careful. :)

> representable in a finite number of digits or bits

Implying a digit-based representation.

> the Unicode string "√5" is representable as 4 UTF-8 bytes

As the other person pointed out, this is representing an irrational number unambiguously in a finite number of bits (8 bits in a byte). I fail to see how your original statement was careful :)

> representable in a finite number of digits or bits

I don’t think those bits unambiguously represent the square root of five. Usually they represent either 3800603189 or -494364107.

Isn't "unambiguous representation" impossible in practice anyway ? Any representation is relative to a formal system.

I can define sqrt(5) in a hard-coded table on a maths program using a few bytes, as well as all the rules for manipulating it in order to end up with correct results.

Well yeah but if we’re being pedantic anyway then “render these bits in UTF-8 in a standard font and ask a human what number it makes them think of” is about as far from an unambiguous numerical representation as you could get.

Of course if you know that you want the square root of five a priori then you can store it in zero bits in the representation where everything represents the square root of five. Bits in memory always represent a choice from some fixed set of possibilities and are meaningless on their own. The only thing that’s unrepresentable is a choice from infinitely many possibilities, for obvious reasons, though of course the bounds of the physical universe will get you much sooner.

Or use pieee-754 which is the same as iee-754 but everything is mimtipled by pi.

i really wanted "mimtipled" to be a word =)

I guess my phone thinks it might be since it didn't correct it :)

Pick a digit, repeat, don't stop.

Exactly right. You can pick and use real numbers, as long as they are only queried to finite precision. There are lots of super cool algorithms for doing this!

That's just saying that you can pick and use rational numbers (which are a subset of the reals.)

Kind of, but you're not just picking rationals, you're picking rationals that are known to converge to a real number with some continuous property.

You might be interested in this paper [1] which builds on top of this approach to simulate arbitrarily precise samples from the continuous normal distribution.

[1] https://dl.acm.org/doi/10.1145/2710016

Not really. You can simulate a probability of 1/x by expanding 1/x in binary and flipping a coin repeatedly, once for each digit, until the coin matches the digit (assign heads and tails to 0 and 1 consistently). If the match happened on 1, then it's a positive result, otherwise negative. This only requires arbitrary but finite precision but the probability is exactly equal to 1/x which isn't rational.

No, it isn't ... an infinite expansion isn't possible.

At no point will your number be transcendental (or even irrational).

That's why you can't stop.

That's irrelevant. It's like saying that you can count to infinity if you never stop counting ... but no, every number in the count is finite.

That's how limits at infinity work.

You seem to be positing that Maxwell's Demon can be reassigned to another impossible task, but that isn't a proper use of his "powers".

Infinities defy simple assumptions about maths, while Maxwell's Demon only needs to ignore the Laws of Thermodynamics.

I'm being serious, not glib, here. "And then do it infinitely many times" doesn't automatically enable any possible outcome, any more than the "multiverse of all possible outcomes" enables hot dog fingers on Jamie Curtis.

No, it certainly isn't.

And don’t die.

How did you test the output of Math.random() for transcendence?

When you apply the same test to the output of Math.PI, does it pass?

All floating point numbers are rational.

All numbers that actually exist in our finite visible universe are rational.

What does "actually exist" mean? Does Pi "actually exist"?

[deleted]

Not really. In all of our physical theories, curved paths are actual curves. So, (assuming circular orbits for a second) the ratio between the length of the Earth's orbit around the Sun and the distance between the Earth and the Sun is Pi - so, either the length of the path or the straight line distance must be an irrational number. While the actual orbit is elliptical instead of circular, the relation still holds.

Of course, we can only measure any quantity up to a finite precision. But the fact that we chose to express the measurement outcome as 3.14159 +- 0.00001 instead of expressing it as Pi +- 0.00001 is an arbitrary choice. If the theory predicts that some path has length equal exactly to 2.54, we are in the same situation - we can't confirm with infinite precision that the measurement is exactly 2.54, we'll still get something like 2.54 +- 0.00001, so it could very well be some irrational number in actual reality.

Well, except for inf, -inf, and nan.

and, depending on how you define the rationals, -0.

https://en.wikipedia.org/wiki/Integer: “An integer is the number zero (0), a positive natural number (1, 2, 3, ...), or the negation of a positive natural number (−1, −2, −3, ...)”

According to that definition, -0 isn’t an integer.

Combining that with https://en.wikipedia.org/wiki/Rational_number: “a rational number is a number that can be expressed as the quotient or fraction p/q of two integers, a numerator p and a non-zero denominator q”

means there’s no way to write -0 as the quotient or fraction p/q of two integers, a numerator p and a non-zero denominator q.

Use an analog computer. Sample a voltage. Congrats.

Sample it with what? An infinite precision ADC?

This is how old temperature-noise based TRNGs can be attacked (modern ones use a different technique, usually a ring-oscillater with whitening... although i have heard noise-based is coming back but i've been out of the loop for a while)

Well, sampling is technically an analog operation that is separate from the conversion operation that makes the result digital. But then analog circuits don't ever actually hold a single real number, in practice there is always noise and that in practice limits the precision to less than what can be fairly easily achieved digitally.

Sure, but we are talking about generating a random number, not sampling noise: those are two different things, albeit the former can be derived from the latter but not directly and as simply as the parent post claimed. Just sampling analog noise does not generate a "true" random number that can satisfy a set of design parameters to configure the NIST 800-90b entropy assessment (well, one could pick shitty parameters for the probability tests, but let's assume experts at the helm). Hence the need for software whitening.

https://en.wikipedia.org/wiki/Hardware_random_number_generat...

https://github.com/usnistgov/SP800-90B_EntropyAssessment

(^^^ this is a fun tool, I recommend playing with it to learn how challenging it is to generate "true" random numbers.)

An infinite precision ADC couldn't be subject to thermal attack because you could just sample more bits of precision. (Of course, then we'd be down to Planck level precision so obviously there are limits, but my point still stands, at least _I_ think it does. :))

Use an analog computer how, to do what? An analog computer can do analog operations on analog signals, but you can't get an irrational number out of it ... this can be viewed as a sort of monad.

[deleted]