Related to : Galton Box Probability

PHP Random Probability 
That will work (with one caveat), although I would still recommend
using mt_rand instead of rand. The main difference is that mt_rand
uses a different PRNG (pseudorandom number generator) engine that
generally provides results that have better randomness than rand. Even
so, this method has an issue, which you may or may not consider
severe.
The potential issue comes from the floating point repres

Matlab Conditional probability from dataset 
Sine your code didn't work by copy & paste, I changed it a little
bit,
It's better if you define a function that calculates the probability
for given data,
function p = prob(data)
n = size(data,1);
uniquedata = unique(data);
p = zeros(length(uniquedata),2);
p(:,2) = uniquedata;
for i = 1 : size(uniquedata,1)
p(i,1) = sum(data == uniquedata(i)) / n;
end
end
Now in another script,
data

Generate N "random" string of length K using probability table 
I'm sure there is a cleaner/better way, but here is one easy way to do
this.
Here we're filling pick_list with the 100 separate characterpair
values, the number of values determined by the probability. In this
case, there are 20 'aa', 30 'ab' and 50 'ac' entries within pick_list.
Then random.choice(pick_list) uniformly pulls a random entry from the
list.
import random
prob_table = {'aa': 0.2

My android app crashes with low probability when it call system gallery to open image 
Do you think this is happening because you are getting a URL instead
and not a local image location? something like getting a picture from
Dropbox or Google drive.
If this is the case then probably you can try this,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
}
Or handle the URL in some other way which is something I have
