Playing with random numbers
Hi everyone I am hoping someone can point out the error in the following code fragment (please excuse the sloppy coding I am just starting to learn c).
First rotation through the for loop correctly returns the hex value however second time around it does not?
First myRand = 4D should result in FFFFFFFF and does
Second myRand = 15FC should result in FFFFFFFA doesn't work?
Code:
srand(length); // seed rand generator
for (i = 0; i < length; ++i) {
myRand = rand(); // get random number
myDivMod = myRand % length;
// myRand = length / 2;
myRand = myRand / length;
myRand = myRand * -1;
myRand = myRand + myDivMod;
//I would like to change string1 directly here instead of using a string2 can I do that?
j = string1[i];
j += myRand;
string2[i] = j;
}
Thanks for taking the time to read this and any suggestions are MOST welcome.
cheers