S
stan
Christopher said:Because, I really wonder what it is exactly you are trying to
accomplish with these posts.
Can you say TROLL?
Christopher said:Because, I really wonder what it is exactly you are trying to
accomplish with these posts.
Do you have to shout at everyone?Razii said:Yeah, this was quicker BUT IT FAILED THE QUALITY TEST..
Yes, that was a consequence of the randomness of the bits in the numbersThe "a" in your string is always more than "z"
Using a better random number function (lrand48()) gives much better
results with bit shifting (deviation of about 0.4%).
If the test showed you that, cut and paste the function exactly so we
can test it. Why didn't you?
Razii said:If the test showed you that, cut and paste the function exactly so we
can test it. Why didn't you?
void getRandomString(std::string &s)
{
int n,i;
srand48(time(0));
s.reserve(len);
for(i = 0 ; i < len; i+=4){
n = lrand48();
s+= (char) (n % 26 + 97);
s+= (char) ( (n>>8) % 26 + 97);
s+= (char) ( (n>>16) % 26 + 97);
s+= (char) ( (n>>24) % 26 + 97);
}
}
void getRandomString( std::string& s, size_t len )
{
srand48(std::time(0));
std::string cr( len, '\0' );
const size_t byN = (len/8)*8;
size_t i(0);
while( i < byN )
{
const int iNumber( lrand48() );
cr[i++] = iNumber % 26 + 97;
cr[i++] = (iNumber>>1) % 26 + 97;
cr[i++] = (iNumber>>2) % 26 + 97;
cr[i++] = (iNumber>>3) % 26 + 97;
cr[i++] = (iNumber>>4) % 26 + 97;
cr[i++] = (iNumber>>5) % 26 + 97;
cr[i++] = (iNumber>>6) % 26 + 97;
cr[i++] = (iNumber>>7) % 26 + 97;
}
while( i < len )
{
const int iNumber( rand() );
cr[i++] = iNumber % 26 + 97;
}
s.swap( cr );
}
Find.cpp(61) : error C3861: 'srand48': identifier not found
Find.cpp(65) : error C3861: 'lrand48': identifier not found
even after I added?
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <stdlib.h>
Razii said:error C3861: 'srand48': identifier not found
I get the following output:
Time: 1.7
Results:
112
105
1929679
1831740
There is something wrong with your testing (I will check your main
later).
There is something wrong with your testing (I will check your main
later).
I am getting this with your function...
C:\>Find a
Number of a: 2596757
Time: 1734 ms
C:\>Find z
Number of z: 870938
Time: 1421 ms
C:\>Find zion
Number of zion: 0
Time: 1484 ms
C:\>Find adam
Number of adam: 0
Time: 1531 ms
The reason why I think something is wrong with your testing is that
when I use my old c++ random function and use the same test, I get
C:\>Find a
Number of a: 1924474
Time: 2578 ms
C:\>Find z
Number of z: 1922329
Time: 2718 ms
C:\>Find zion
Number of zion: 112
Time: 2656 ms
C:\>Find adam
Number of adam: 99
Time: 2515 ms
So obviously my test is correct...
Btw i think its important to mention that here the java version is
taking ~100mb ram while the C++ version uses only 50 mb.
This topic was on these newsgroups 7 years ago
No, when I wrote "..." I meant "insert your old code, exactly as it was, here".
Ok, so I have this now...
void getRandomString( std::string& s, size_t len )
{
srand((unsigned)std::time(0));
std::string cr( len, '\0' );
for( int i = 0 ; i < len ; ++i )
{
int iNumber;
iNumber = rand() % 26 + 97;
cr = (char) iNumber;
}
s.swap( cr );
}
Time: 2531 ms
that's still slower than java version..
Time: 1719 ms
#include <iostream>Find.cpp
import java.util.*;cat Find.java
Time: 3654 msjava -Xmx256m Find && ./Find
I could not start the -sever flavour of java, perhaps it makes a difference.
I could not start the -sever flavour of java, perhaps it makes a difference.
Michael said:I could not start the -sever [sic] flavour of java, perhaps it makes a
difference.
Razii said:The -server version is in JDK bin directory....If your path is set to
check the JDK bin directory first, -server sould work.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.