#ThisWeeksFiddler, 20260619

This week the #puzzle is: Can You Fix the Random Number Generator? #probabilities #montecarlo #coding #expectedvalue

I think the random number generator on my calculator might be malfunctioning. Oh no!
Under normal conditions, it should generate random numbers between 0 and 1. But my suspicion is that the calculator is “tanked,” meaning it only generates random numbers between 0 and some value 0 < a < 1. Beyond that, I have no knowledge regarding the value of a. At the moment, it’s equally likely to be any value from 0 to 1.
As an experiment, I ask the calculator to generate one random number. It produces a value of exactly 0.5. (While this is, admittedly, infinitely unlikely, let’s roll with it!)
Based on this result, what can I expect the value of a to be, on average?

And for extra credit:

Frustrated with my old calculator, I toss it in the trash and buy a new one. But now I’m concerned this second calculator is also “tanked.” As before, every value of a between 0 and 1 is equally likely at first.
I ask my friend to generate one random number using this second calculator. My friend does so, and smirks. “I won’t tell you what the number is,” my friend says, “but it’s somewhere between 0 and 0.5.”
On average, what can I expect the value of a (for this second calculator) to be?

Can You Fix the Random Number Generator?

Solution, possibly incorrect:

Program

Method 1: Something, something, sums, integrals. PDFs? I got stuck.

Method 2: Monte Carlo. Choose a random a, then produce a random output for the calculator. (If r is a random number 0-1, then ra is a random number 0-a. Neat.) If that random output is reasonably close to 0.5 (within a difference of Δ\Delta), use that a to calculate the average a.

actual loops   good loops        delta    average a
71468147 10000000 0.100000 0.714385
360434645 10000000 0.020000 0.721046
1803734570 10000000 0.004000 0.721364
9014346353 10000000 0.000800 0.721287
45085162688 10000000 0.000160 0.721386

Result: 0.721. We know a is somewhere between 0.5 and 1, so that makes sense.

And for extra credit:

Still monte carlo. Choose a random a, then produce a random output for the calculator. If that random number is 0.5 or below, use that a.

actual loops   good loops                 average a
11812250 10000000 0.442937

Result: 0.443. The lower the a, the higher the chance of producing an output below 0.5. Makes sense.

This was actually much easier as monte carlo!

Skriv en kommentar