M
Moritz Beller
Dear programmers,
Have a look at this function to generate random numbers from 1 to count.
It simply does not work. Well, actually it compiles silently, but then
returns "1" (Compiler: gcc/++ 3.3.2-r5; Gentoo Linux).
#include <cstdlib> // For random number generator
#include <ctime> // For time function
using namespace std;
inline int random(int count) {
return 1 +
static_cast<int>((count*static_cast<long>(rand()))/(RAND_MAX+1));
}
I was able to find out that the command _will_ work as it is expected
with out RAND_MAX, but obviously doesn't make any sense, then.
Thanks in advance,
Moritz Beller
Have a look at this function to generate random numbers from 1 to count.
It simply does not work. Well, actually it compiles silently, but then
returns "1" (Compiler: gcc/++ 3.3.2-r5; Gentoo Linux).
#include <cstdlib> // For random number generator
#include <ctime> // For time function
using namespace std;
inline int random(int count) {
return 1 +
static_cast<int>((count*static_cast<long>(rand()))/(RAND_MAX+1));
}
I was able to find out that the command _will_ work as it is expected
with out RAND_MAX, but obviously doesn't make any sense, then.
Thanks in advance,
Moritz Beller