# Perfect Thirds: uniformly choosing among 3 options

proof of concept (fully functional)

It’s easy to get the EV: Nova engine to choose between two things with equal probability—just use the R operator in a Set expression. By induction, it’s not too hard to get any fraction whose denominator is a whole power of 2. But to choose among three things with equal probability, that’s much trickier.

You could use a crön with a 33 or 34 percent chance of firing, but that requires a day to pass each time you want to trigger the effect. You could use a mïsn with a 33 or 34 percent chance of being offered, but that requires the player to land and it prevents other random missions from being offered. Plus those are still just approximations of an even split at 33:33:34 ratios.

We really want something that can go in any Set expression and will choose among three options with uniform probability. Here is my proof of concept plug-in: PerfectThirds.zip (37K)

Using it, go to any outfitter and buy the Perfect Thirds outfit. This will randomly grant one of three other outfits. Although this demonstration involves landing and buying an outfit, the methodology could be applied to any Set expression and it would work just fine. It could be done when observing a mission ship, when completing a mission, or even from a crön.

I set the Perfect Thirds outfit to have a maximum of 30,000. However, buying that many all at once may take a few seconds to process. On my computer it takes around 5 seconds. Buying a few hundred or even a thousand at a time you shouldn’t notice any delays though.

Edit: Fixed a bug.

This post has been edited by Qaanol : 10 February 2011 - 07:58 AM

Cool, I see how it works:

An outfit triggers first mission
First mission - OnAccept: A1 R(S2 S3) - randomly trigger mission two or three
Second mission - OnAccept: A2 R(S1 G2) - 50/50 chance of giving outfit 2, or triggering mission one again
Third mission - OnAccept: A3 R(G1 G3) - 50/50 chance of giving outfit 1 or 3.

@lnsu, on 10 February 2011 - 02:57 PM, said in Perfect Thirds: uniformly choosing among 3 options:

Cool, I see how it works:

An outfit triggers first mission
First mission - OnAccept: A1 R(S2 S3) - randomly trigger mission two or three
Second mission - OnAccept: A2 R(S1 G2) - 50/50 chance of giving outfit 2, or triggering mission one again
Third mission - OnAccept: A3 R(G1 G3) - 50/50 chance of giving outfit 1 or 3.

Yup, that’s how it works. If we just wanted a 1/3 chance of G2 and 2/3 chance of G1 we could do:
Mission 1 — OnAccept: A1 R(S2 G1)
Mission 2 — OnAccept: A2 R(S1 G2)

And we could do a perfect fifth as follows::
Mission 1 — OnAccept: A1 R(S2 G1)
Mission 2 — OnAccept: A2 R(S1 S3)
Mission 3 — OnAccept: A3 R(S1 G2)

A perfect sixth would just be a perfect third with a bifurcation:
Mission 1 — OnAccept: A1 R(S2 G1)
Mission 2 — OnAccept: A2 R(S1 S3)
Mission 3 — OnAccept: A3 R(G1 G2)

And a perfect seventh:
Mission 1 — OnAccept: A1 R(S2 G1)
Mission 2 — OnAccept: A2 R(S3 G1)
Mission 3 — OnAccept: A3 R(S4 G2)

Note for these last three I made the odds of getting a G2 to be 1/5, 1/6, and 1/7 respectively, and the odds of getting G1 to be 4/5, 5/6, and 6/7 respectively. If you want to split the 4/5 down into 4 equal parts that’s easy, just use 3 more missions to bifurcate twice for a total of 6 missions for five fifth. Splitting the 5/6 into 5 equal parts is a matter of not lumping them all together in the first place, so you have a 1/6 and a 4/6, which takes three missions to split the 4/6 in four for a total of 6 missions for six sixth. Splitting the 6/7 down into 6 equal parts requires four more missions, for a total of 7 missions for seven seventh.

This post has been edited by Qaanol : 10 February 2011 - 07:37 PM

If you don’t need to grant an outfit immediately , but are content to be able to check which of three (or however many) options to follow (say, when the next mission is offered) then you don’t need any extra missions. For example, with n=3 you only need two missions:

Initial Set expression that starts the sequence: R(b1) S1 <whatever else you want>
Mission 1 — OnAccept: A1 R(S2)
Mission 2 — OnAccept: A2 R(S1 b2)

This gives the following three outcomes with equal probability:
b2
!b2 & b1
!b2 & !b1

Similarly for n=7 you only need three missions:
Initial Set expression that starts the sequence: R(b1) R(b2) S1 <whatever else you want>
Mission 1 — OnAccept: A1 R(S2)
Mission 2 — OnAccept: A2 R(S3 b3)
Mission 3 — OnAccept: A3 R(S1 b4)

Here are 7 equally likely outcomes:
b4
!b4 & (b3 & b2)
!b4 & (b3 & !b2)
(!b4 & !b3) & (b2 & b1)
(!b4 & !b3) & (b2 & !b1)
(!b4 & !b3) & (!b2 & b1)
(!b4 & !b3) & (!b2 & !b1)

If you aren’t assured that all relevant bits will start off cleared, you can use the initial Set expression to randomize the random ones and clear the ones that need to be cleared. This also allows the same batch of perfect nths missions to be reused as needed:

Initial Set expression for repeatable perfect thirds: R(^b1) !b2 S1 <whatever else you want>
Initial Set expression for repeatable perfect sevenths: R(^b1) R(^b2) !b3 !b4 S1 <whatever else you want>

You get the idea. If anyone wants an explanation why this method works to create perfect thirds (or nths), just let me know and I’ll write it up.