Random Golf of the Day #7: A distinctly random character
MATL, 6 Characters
1Y2Xr)
Explanation:
Xr
Take a normally distributed random number
)
Use this to index into...
1Y2
The alphabet
The distribution is symmetrical around 0, and the translation of number to char is symmetrical around 0.5. As such the probabilities should be distinct.
05AB1E, 6 bytes
Code
A.pJ.R
Explanation
A # Pushes the alphabet
.p # Computes all prefixes
J # Join them together
We now have the following string:
aababcabcdabcdeabcdefabcdefgabcdefghabcdefghiabcdefghijabcdefghijkabcdefghijklabcdefghijklmabcdefghijklmnabcdefghijklmnoabcdefghijklmnopabcdefghijklmnopqabcdefghijklmnopqrabcdefghijklmnopqrsabcdefghijklmnopqrstabcdefghijklmnopqrstuabcdefghijklmnopqrstuvabcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwxabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyz
After that, we pick a random element using .R
.
The probabilities
a > 7.4074074074074066%
b > 7.122507122507122%
c > 6.837606837606838%
d > 6.552706552706553%
e > 6.267806267806268%
f > 5.982905982905983%
g > 5.698005698005698%
h > 5.413105413105414%
i > 5.128205128205128%
j > 4.843304843304843%
k > 4.5584045584045585%
l > 4.273504273504274%
m > 3.988603988603989%
n > 3.7037037037037033%
o > 3.418803418803419%
p > 3.133903133903134%
q > 2.849002849002849%
r > 2.564102564102564%
s > 2.2792022792022792%
t > 1.9943019943019944%
u > 1.7094017094017095%
v > 1.4245014245014245%
w > 1.1396011396011396%
x > 0.8547008547008548%
y > 0.5698005698005698%
z > 0.2849002849002849%
Try it online!.
Jelly, 5 bytes
ØA»ẊX
Try it online!
How it works
ØA«ẊX Main link. No arguments.
ØA Set argument and return value to the alphabet.
Ẋ Shuffle it.
» Yield the maximum of each letter in the sorted alphabet, and the
corresponding character in the shuffled one.
X Pseudo-randomly select a letter of the resulting array.
Background
Let L0, …, L25 denotes the letters of the alphabet in their natural order, and S0, …, S25 a uniformly at random selected permutation of L. Define the finite sequence M by Mn = max(Ln, Sn).
Fix n in 0, … 25 and define k as the index such that Ln = Sk.
With probability 1 / 26, Ln = Sn and n = k, so Mn = Ln and Ln occurrs once in M.
With probability 25 /26, Ln ≠ Sn and n ≠ k. In this case, the following happens.
With probability n / 25, Sn is one of L0, …, Ln - 1, so Ln > Sn and Mn = Ln.
Independently, also with probability n / 25, k is one of 0, … n - 1, so Sk > Lk and Mk = Sk = Ln.
Thus, the expected number of occurrences of Ln in M is 1/26 + 25/26 · (n/25 + n/25) = (2n + 1)/26.
Finally, if we now select a term m of M uniformly at random, the letter Ln we be chosen with probability (2n + 1)/26 / 26 = (2n + 1)/676.
This yields the following distribution of probabilities.
p(m = A) = 1/676 ≈ 0.00148
p(m = B) = 3/676 ≈ 0.00444
p(m = C) = 5/676 ≈ 0.00740
p(m = D) = 7/676 ≈ 0.01036
p(m = E) = 9/676 ≈ 0.01331
p(m = F) = 11/676 ≈ 0.01627
p(m = G) = 13/676 ≈ 0.01923
p(m = H) = 15/676 ≈ 0.02219
p(m = I) = 17/676 ≈ 0.02515
p(m = J) = 19/676 ≈ 0.02811
p(m = K) = 21/676 ≈ 0.03107
p(m = L) = 23/676 ≈ 0.03402
p(m = M) = 25/676 ≈ 0.03698
p(m = N) = 27/676 ≈ 0.03994
p(m = O) = 29/676 ≈ 0.04290
p(m = P) = 31/676 ≈ 0.04586
p(m = Q) = 33/676 ≈ 0.04882
p(m = R) = 35/676 ≈ 0.05178
p(m = S) = 37/676 ≈ 0.05473
p(m = T) = 39/676 ≈ 0.05769
p(m = U) = 41/676 ≈ 0.06065
p(m = V) = 43/676 ≈ 0.06361
p(m = W) = 45/676 ≈ 0.06657
p(m = X) = 47/676 ≈ 0.06953
p(m = Y) = 49/676 ≈ 0.07249
p(m = Z) = 51/676 ≈ 0.07544
You can empirically verify the distribution by calling the link 100,000 times (takes a few seconds).