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 <[email protected]> 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 [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
-~----------~----~----~----~------~----~------~--~---