You are provided with a bit generator which generates 1 and 0 with equal
probabilities i.e. (1/2). You are required to design a function which
generates numbers form 1-1000 with equal probabilities i.e. (1/1000).
--
You received this message because you are subscribed to the Google Groups
int a=(int)rand()%1001; //1-1000
int b=(int)rand()%2; // 0-1
On Fri, Jul 15, 2011 at 3:01 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote:
You are provided with a bit generator which generates 1 and 0 with equal
probabilities i.e. (1/2). You are required to design a function which
generates
@sagar
did you read the question before posting
On Fri, Jul 15, 2011 at 3:17 PM, sagar pareek sagarpar...@gmail.com wrote:
int a=(int)rand()%1001; //1-1000
int b=(int)rand()%2; // 0-1
On Fri, Jul 15, 2011 at 3:01 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote:
You are provided with a
oh sorry...
On Fri, Jul 15, 2011 at 3:21 PM, sunny agrawal sunny816.i...@gmail.comwrote:
@sagar
did you read the question before posting
On Fri, Jul 15, 2011 at 3:17 PM, sagar pareek sagarpar...@gmail.comwrote:
int a=(int)rand()%1001; //1-1000
int b=(int)rand()%2; // 0-1
On Fri, Jul
If rand() generates equi-probable numbers within range [1 - n] and n is a
multiple of 1000 then your above code will be correct.
You should utilize the bit-generator function.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this
Read Dave solution
https://groups.google.com/forum/#!msg/algogeeks/nE3REQZ-YBc/Y02NVHYBhdkJ
On Fri, Jul 15, 2011 at 3:23 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote:
If rand() generates equi-probable numbers within range [1 - n] and n is a
multiple of 1000 then your above code will be
its correct.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this
int bit_generator(); // function which returns 1 and 0 with equal probabilities
int generator()
{
int generated_num[10],i,n;
for(i=0;i10;i++)
{
generated_num[i]=bit_generator();
}
n=generated_num[0];
i=1;
while(i10)
{
n*=10;
I don't think so that probability would be exact 1/1000 .
suppose number is ( a9 a8 a7 a6 a5 a4 a3 a2 a1 a0) where a0 is least and a9
is most significant bit then you can generate each of the bit ai using given
bit generator
but if but at a time (a9 , a8 , a7 , a6 , a5 , a3 ) and any other bit
nos [1001,1023] are neglected as if their probabilities are set to zero and
recalculated.As nos [1,1000] are only considered and as they are generated
with equal probabilities i.e. 1/1024. I feel the above solution to be
correct.
--
You received this message because you are subscribed to the
but suppose you have to generate numbers between [1,513] then also it would
generate numbers them each with probability 1/1024 which could make a big
difference and I feel the above solution to be incorrect . May be we could
think of a better one .
--
You received this message because you are
@rishab, here it generates numbers which are powers of 2 until n gets to 0
int bit_generator(); // function which returns 1 and 0 with equal
probabilities
int generator(int n)
{
int generated_num[10],i;
int lg = (int)floor(log(n));
n -= pow(lg,2);
int m = 0;
i=0;
@Surender Your solution in correct one .
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
13 matches
Mail list logo