Choosing randomly two integer numbers from 10 to 1,000,000 inclusive,
What are the chances they will be represented:
a. each by two distinct digits, albeit different
for each one of the numbers e.g. 322 and 78778
b.exactly the same two, like 3334 and 433344
or
c. distinct couples, sharing one digit like 5558 and 88338
This program has a bug, highlighted below, and corrected in my later post. Therefore the results are wrong.
clearvars,clc
typea=0; typeb=0; typec=0;
for trial=1:100000000
n1=char(string(randi(999991)+9));
if length(unique(n1))==2
n2=char(string(randi(999991)+9));
if length(unique(n1))==2
switch length(unique([n1 n2]))
case 2
typeb=typeb+1;
case 3
typec=typec+1;
case 4
typea=typea+1;
end
end
end
end
typea
typeb
typec
typea/trial
typeb/trial
typec/trial
trial/typea
trial/typeb
trial/typec
provides a limited view of the probabilities:
In 100 million trials, these are the numbers of cases of the three types:
typea =
40367
typeb =
62
typec =
3266
That's enough to get about 2-digit accuracy in types a and c, and less than that in type b.
Those probabilities were calculated at:
ans =
0.00040367
ans =
6.2e-07
ans =
3.266e-05
and the reciprocals (for 1 in ... form):
ans =
2477.27103822429
ans =
1612903.22580645
ans =
30618.4935701163
Both sets are a, b, c order.
Edited on July 14, 2023, 11:49 am
|
Posted by Charlie
on 2023-07-14 09:37:54 |