From: Suvania on 4 Jun 2010 07:37 Hi, I would like randomize the binary bits '0' and '1', with 51% probability of it being '0', and 49% probability of it being '1'. I have used the following: bits = rand(1,nbits)<=0.49 But rand generates numbers with uniform distribution. The numbers generated will range from 0 to 1, but will the random numbers represent 49%/51% probability?? Regards Su
From: Steven Lord on 4 Jun 2010 09:18 "Suvania " <smoodliar(a)gmail.com> wrote in message news:huaogv$rb$1(a)fred.mathworks.com... > Hi, > > I would like randomize the binary bits '0' and '1', with 51% probability > of it being '0', and 49% probability of it being '1'. > > I have used the following: > > bits = rand(1,nbits)<=0.49 > > But rand generates numbers with uniform distribution. The numbers > generated will range from 0 to 1, but will the random numbers represent > 49%/51% probability?? What is the probability that a number drawn from the uniform distribution on the interval (0, 1) will be less than or equal to 0.49? If you want to control not the probability but the percentage of 0's and 1's: numZeros = round(nbits/100*51); numOnes = round(nbits/100*49); bits = [false(1, numZeros) true(1, numOnes)]; bits = bits(randperm(length(bits))); You might need to tweak this a bit if nbits is not exactly divisible by 100. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
|
Pages: 1 Prev: Need helps for some work in matrix Next: Space dividing algorithm help? |