PDA

View Full Version : This makes no sense!


rock freak
November 3rd, 2005, 07:54 PM
if(m=='y'){
i=0;
}
else{
i=1;
}

gives me this error on compiling
warning: comparision between pointer and interger

But i cant see why!! its doing my head in

tehwa
November 3rd, 2005, 07:56 PM
which language?

rock freak
November 3rd, 2005, 07:57 PM
Dont worry all sorted just tooka quick break from it. went back to it and saw it straight away!

rock freak
November 3rd, 2005, 08:04 PM
the rand function in C is totally usless for getting random numbers. and the srand is great

anyone know how to make totally or near to it random number generator? this is the code im using at the mo

srand((unsigned)time(NULL));
random=rand()%10

ltmon
November 3rd, 2005, 09:03 PM
All (well all standard) computerised random-number generators are really just psuedo-random. It's just a mathematical function that produces numbers in a sequence.

srand helps because it has a seed (in your case you are using the time) which will cause it to be different every time. rand doesn't have a seed, so the sequence of "random" numbers will be identical every time you run your program.

You may have seen some programs that make you move the mouse around the screen while it generates the number.... this is because it is using your mouse movements as the seed.

Other (high level) generators use static electricity or electron states as seeds, but that is beyond what a PC can do without special hardware :)

Unless you are going for some military-grade cryptography, using the current time as a seed should be fine.

L.