Generate random bits array of 0 and 1 with fixed number of set bits

hello @aattuull

please share the problem link with me

there is not any such problem,
It is just a small part of my project code

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Nops above doubt is still pending

@aattuull
actually bro i m not getting ur doubt, pls explain what exaclty u want.
if possible give some sample examples

I want to generate array which should contain fix amount of bits as 1 given by user …
Ex :- say array of size 10 with 4 set bits then output should be
1000100110

And every time array generate random set of bits with given fix amount of set bits

i.e.
1000101010
Next time it might be
0000110110

ok ,so u can do like this->

generate all such number(binary array) that are having required number of set bits ,store then in array or vector.

now use random function to randomly pick any index of the generated array and then simply return that number(binary array)