How about :

int random(a,b)
{
 if(a==b)
 return a ;
 mid = a + (b-a)/2 ;

 if( rand() )
 return random(mid,b) ;

 else
 return random(a,mid) ;
}

Assuming that rand() returns 0 and 1 randomly


On Tue, Oct 6, 2009 at 10:34 AM, gold007 <agarwalha...@gmail.com> wrote:

>
> how can we generate random values which lie in the range [a,b] or
> wrire a function for the same....
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to