well... you're mulpitplying rangenum by a random number... who says that result can fit into an integer?
dont' forget that's happening before it gets promoted to a floating-point number...
this code
Code:
#include <iostream>
#include <ctime>
int main()
{
srand(static_cast<short int>(time(0)));
int x;
for(int i=0;i<10;i++)
{
x=50*rand()/(RAND_MAX+1.0);
std::cout<<x<<std::endl;
}
}
results in this output
Code:
-1279308866
1370173278
-633427736
445617742
-2042006872
623654194
-806845720
-1524802060
431276324
542628534
and the rest of the equation:
Code:
#include <iostream>
#include <ctime>
int main()
{
srand(static_cast<short int>(time(0)));
int x;
for(int i=0;i<10;i++)
{
x=1+int(50*rand()/(RAND_MAX+1.0));
std::cout<<x<<std::endl;
}
}
results in:
Code:
xxxxx@MCP ~/Programming/C++ $ g++ test.cpp -Wall -w -ansi -pedantic -o test.exe && ./test.exe
1
1
1
1
1
1
1
1
1
1