Given t and p, I need to generate a bit array b of dimension p with exactly t ones chosen randomly.
For example if t=5 and p=2, possible versions of b are:
[0,1,0,1,0]
[1,1,0,0,0]
[1,0,0,0,1]
And many others...Is there any easy way to create it in C++?
Note: it's important that the position where 1 appears are chosen randomly
Aucun commentaire:
Enregistrer un commentaire