call function and save each of the results in x and y(say)
if x = 0 and y = 1 ...prob = (.6)*(.4) return 0
if x = 1 and y = 0 ...prob = (.4)*(.6) return 1
otherwise, repeat..
hence this new function will return 0 and 1 with 50% prob.


On Tue, Mar 22, 2011 at 11:07 PM, Don <[email protected]> wrote:

> Which is why stating the requirements precisely is important.
> If modeling a coin toss is the goal, this should work.
>
> bool uniform()
> {
>        static unsigned int x = 1234567;
>        x = 63663*(x&65535)+(x>>16);
>        return ((x&64)==0) ^ nonUniform();
> }
>
> On Mar 17, 3:29 pm, Dave <[email protected]> wrote:
> > @Don: Clever and efficient code to meet the problem statement
> > precisely. It does give true on half of the calls, but it doesn't give
> > true with probability 50% on any given call, so we wouldn't want to
> > use it to model a fair coin.
> >
> > Dave
> >
> > On Mar 17, 1:03 pm, Don <[email protected]> wrote:
> >
> > > bool uniform()
> > > {
> > >   static bool state = true;
> > >   state = !state;
> > >   return state ^ nonuniform();
> >
> > > }
> >
> > > On Mar 17, 9:24 am, saurabh agrawal <[email protected]> wrote:
> >
> > > > Given a  function which returns true 60% time and false 40% time.
> >
> > > > Using this function you have to write a function which returns true
> 50% of
> > > > the time.- Hide quoted text -
> >
> > > - Show quoted text -
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
thezeitgeistmovement.com

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to