by aaaaaa123456789/asdf14396

version 1.1, updated 15 July 2017

Table of contents

Version 1.1 (15 July 2017):

Expanded concept of normally generated badge

Introduced normal/existing weighting and effective rarity

Adjusted formulas to account for weighting

Version 1.0 (3 December 2016):

Initial version

Badge transmutation takes a certain number of input badges (at least 3 as currently implemented, with no upper bound), and produces a single output badge as an output. The determination of the output as a function of the inputs is a random process, which is governed by rarities.

Rarities are affected by whether a certain badge is normally generated or not. (Note that this concept applies to individual instances of badges, not to the species.) A badge is considered to be normally generated if it is not the product of a transmutation. Note that this concept therefore doesn't account for badges removed from circulation due to being used as transmutation inputs, nor for badges introduced into circulation due to being the output of a transmutation process.

The rarity of a badge is a value between 0 and 1 which indicates the proportion of badges of that species with respect to all badges. This value combines the proportion of normally generated badges of that species to all normally generated badges (normal rarity) and the proportion of badges of that species currently in existence to all existing badges (existing rarity). Note that a lower number means that the badge is rarer, and thus more desirable.

The transmutation process consists of several calculations, performed in sequence. The process is as follows:

Determine the rarity of the inputs Create a random extra input Calculate the mean output from the inputs Generate a random output rarity according to the calculated mean Determine the output corresponding to that rarity

The second step merely generates a random value in (0, 1] and adds it to the input list, treating it as if it was an extra input rarity. (Note that the interval is (0, 1], not [0, 1). Most programming languages provide a function to do the latter. This can easily be converted to the former by doing 1.0 - random() .)

The remaining steps use their own formulas and procedures, described in the following sections of this document.

4. Rarity calculation¶

In order to determine the effective rarity value to be used for the rest of the calculations (which will be simply referred to as "rarity" elsewhere in this document), two values must be calculated: the normal rarity and the existing rarity.

The normal rarity is the quotient between the number of normally generated badges of the species under calculation and the number of normally generated badges of all species; this indicates the proportion of badges of that species that have been generated via normal means (e.g., pinball or runs). The existing rarity, on the other hand, is the corresponding quotient between the number of existing badges of the species under calculation and the total number of existing badges; this indicates the proportion of badges of that species currently in circulation.

The effective rarity is calculated as a weighted average between these two values. The existing rarity is multiplied by the weighting factor w, and the normal rarity is multiplied by its complement (1 - w); the effective rarity is the sum of these two values. This rarity is the value that will be used throughout the rest of this document.

The weighting factor is currently set to w = 0.2.

5. Mean output calculation¶

Let there be n input badges, each one having an individual rarity value of r i (for i from 1 to n). Let r 0 be the rarity of the random extra input calculated in the previous step.

The mean output, m, is calculated as follows:

Note that both the tangent and arctangent functions use angles in radians.

6. Random output distribution¶

The random output generation uses a specific distribution, to be described here. (The exact process will be described in the next section.)

The distribution takes two parameters, m and p. The m parameter is the mean and median of the distribution; the p parameter is simply a shape parameter. In the following formulas, for simplicity, another variable c = 1 - m is used.

The probability density function takes this form:

Therefore, the cumulative distribution function takes this form:

And finally, the inverse of the above function, the quantile function, takes this form:

7. Random output generation¶

In order to generate the random output rarity, the distribution from the previous section is used. The m parameter for the distribution is simply the mean output calculated in the previous step, and the p parameter is calculated as a function of the m parameter and N, the weighted total number of badges.

The weighted total number of badges, N, is calculated as a function of the total number of badges normally generated (let this be N N ) and the total number of badges in existence (let this be N E ). Using the same weighting factor w as for rarity calculation, the value of N is calculated as follows:

With this value of N, and the previously calculated m, the value of the parameter p is calculated as follows:

Note that, due to the form of the above formula, any logarithm base can be used; the result will be the same. A common choice for logarithm base is the natural logarithm (ln), which is directly available in most programming languages. (Another simple choice is to use base 2 logarithms, which would cause the log 2 term to reduce to 1.)

This value of the parameter was chosen so that, for mN > 1, the probability of generating a value lower than 1/N is 1/(1 + mN). (Note that 1/N is the rarity of a badge for which only one copy has been generated normally and only one copy still circulates.) In order to get a badge that is rarer than this, the generated output value must be lower than 1/N; therefore, this directly affects the probabilities of getting such a badge. (The exact probabilities are subject to the final output determination to be explained in the next section.) For mN < 1, the probability of generating a value lower than 1/N is already greater than 1/2 (because m is also the median of the distribution, and m < 1/N), so no special care was taken for this case.

Any method of generating a random value with a given distribution will work. A simple method, usable with the above distribution, is to generate a random value between 0 and 1 and apply the quantile function (the last function shown in the previous section) to it.

8. Final output determination¶

The output rarity calculated in the previous step determines the output badge from the process. If there is at least one badge with that exact rarity, one of them is selected at random and the process is done; however, that will rarely be the case, because the distribution is continuous and the badge rarities are not.

Let R be the final calculated rarity. Of all the rarities that do exist (i.e., for which there are badges with that rarity), find the closest ones to R from both sides (that is, the closest one smaller than R and the closest one larger than R); let those two values respectively be L and H, so that L < R < H.

Now generate a random number between L and H. (Many programming languages provide a way of doing so directly; otherwise, generate a random number r between 0 and 1 and calculate Lr + H(1 - r) to generate a random number between L and H.) If the generated number is less than R, select the badge with rarity H; otherwise, select the badge with rarity L. (If more than one badge exists for the selected rarity, select one of them at random.)

This finally determines which badge comes out of the transmutation process.