Because the call to rand() produces the random number.
1 2 3 4 5 6
x = rand(); // this generates 1 random number and puts it in 'x'
while (1)
{
cout << x; // this prints whatever is in 'x'. It does not change 'x'
cin.ignore();
}
Say for example, rand() produces the number 156. That means x=156.
When you loop, you're printing x (156). Since you never change the contents of x, you'll keep printing 156 over and over.
On the other hand, if you move the call to rand() inside the loop, then you'll get a different number:
1 2 3 4 5 6
while (1)
{
x = rand(); // now x is set to a new random number every time the loop runs
cout << x; // so this will print different numbers each time
cin.ignore();
}