hey, I am just trying to generate a random string with a set length for a key to be later used to XOR "encrypt" some data. here is the code I am using now:
Code:
void RandCryptKey(char *szIn)
{
int i;
srand(GetTickCount());
do i = rand();
while(i < 10000 && i > 1000);
wsprintf(szIn, "%d", i);
}
this function is being called in a loop by the way. now here is my problem, other than the fact that this is a rather inefficient method, I guess my code is looping so fast, that the same key is being generated for each call (I guess the seed is remaining the same). not to mention the fact that I am looking for a 4 digit number for the string, and the above code will still generate 5 digit numbers, even with my do while loop's conditional.
GetTickCount is a Win32 API call to return the amount of time that the system has been running for in milliseconds by the way. and think of wsprintf as sprintf, it is simply the Win32 version since I am not including stdio.h.
so as you see I am having quite the problems here, and I can't think of any other way to go about this.
could anyone please help me out with an idea for an alternative method for doing this here please?
any help/input is greatly appreciated. thank you in advance!