lundi 18 avril 2022

Unbalanced random binary sequence generator

I’m trying to write a function to generate binary sequence which is unbalanced. Unbalanced means P(0) = 1/2 + bias, P(1) = 1/2 - bias, P(0) + P(1) = 1. bias can be negative

auto genenator(int length, int bias) {
       std::vector<int> result;
       ......
       return result;
}

For example, res = generator(20, 0.1).

res may = {0,0,1,0,1,0,0,1,0,1,1,0,1,1,0,0,0,1,0,0}, there are twelve 0 and eight 1, so P(0) = 12 / 20 = 0.6, P(1) = 0.4.

I only found this https://www.geeksforgeeks.org/generate-a-random-binary-string-of-length-n/




Aucun commentaire:

Enregistrer un commentaire