Hi,
I have a program that takes a seed and generates a random number using srand and rand, however there is another requirement to it that I don't understand and am hoping that you may make sense of. The instructions say:
Do you know what bitwise ANDing 0x7FFF is? The code I have is:The random number seed must be set using the srand function in stdlib.h. Random number must be generated by bitwise ANDing (&) 0x7FFF with the value return by the rand function in stdlib.h.
Code:#include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { int seed; int randnum; seed = 65445321; cout << "Generating a random number...\n"; srand(seed); randnum = rand(); cout << randnum << "\n"; system("Pause"); return 0; }



LinkBack URL
About LinkBacks



