Z
zionztp
No, in that case, we are comparing c++ library vs java library.
I meant that we are not sure how good are the numbers java/c++
produce, since "more random" numbers usually take more time to
generate, so we would need to know that both C++/Java are producing
equally good numbers before trying to compare speed.
I deleted the code i used to test, i've just rewritten it using
std:string since i was using plain arrays, this one runs 2x slower but
still faster than the original code:
const int len = 50000000;
void randomString(std::string &s)
{
char cr[len];
int n;
unsigned char tn[4];
srand((unsigned)std::time(0));
for( int i = 0 ; i < len; i+=4 ){
n = rand();
memcpy(tn, &n, 4);
s+= (char) (tn[0] % 26 + 97);
s+= (char) (tn[1] % 26 + 97);
s+= (char) (tn[2] % 26 + 97);
s+= (char) (tn[3] % 26 + 97);
}
}
int main()
{
std::string s;
randomString(s);
}
compiled with:
g++ code.cpp -O3
btw could you provide the full java code so i can test both?