rand() not working and understanding extended gcd
<p>This simple code:</p>

<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
using namespace std;
int main()

{

cout &lt;&lt; rand();

}
</code></pre>

<p>seems to produce 16807 every time the code is executed when it should produce a random number 
between 0 and RAND_MAX. Have I missed something in the code?</p>

<p>On another subject; I've been looking at the book 'C++ for Mathematicians' and have successfully compiled the code for the extended gcd problem but I don't understand this part:</p>

<pre><code>//set up recursion
long aa=b;
long bb = a%b;
long qq =a/b;
long xx,yy;

d=gcd(aa,bb,xx,yy);

x=yy;
y=xx -qq*yy;

return d;
</code></pre>

<p>This seems to generate both the d=gcd(a,b) and two numbers x,y such that d=ax+by, (a>0,b>0) using recursion. I was wondering if someone could explain/give insight into how this part of the code works?
In the book it explains the maths and then says 'these ideas form the heart of recursion' but I can't understand it. </p>

<p>Thanks.</p>
