I missed a class on Wednesday and am having some problems figuring out the next assignment, if someone could IM me at GeraldC69 on aim so I could get some things clarified that would be awesome.
_________________ "Suche gut gebauten Achtzehn- bis Dreißigjährigen zum Schlachten"
Der Metzgermeister
Joined: Tue 08-19-2003 11:48PM Posts: 95 Location: A country within a closet.
Source: TJ North
I'm in Sea's class, so this may not be what Price wants, but it should work.
First you need to seed the function. We're using the system time to do so. The statement is "srand(time(NULL));" You'll need to include the <ctime> library.
To generate actual numbers, call the function "rand(max)", where "max" is the integer set as the maximum parameter. For a minimum, you'll need to put the "rand" function in a do-while loop until it gives you a value greater than the minimum. The "rand" function is in the <cstdlib> library, so you need to include that, too.
And if all else fails, look in the textbook. Page 965, I think.
Hope that helps.
_________________ "Didn't the pirates take everything already?"
"They left everything that was nailed down. I did not."
lol, I've somewhat gotten past that, now I'm just kinda screwed on how I fit all these functions together correctly. Our program has to have 7 functions in it and It's really getting complicated the way I'm trying to do it, I've got to be doing it wrong somehow. I could do this no problem with the use of only 2 or 3 functions but linking 7 of them together seems to be really tough. I think it might be his dirrections that are throwing me off more then anything though, there is no way I'm going to finish this assignment and I've probably spent over 8 hours on it. lol, my grade is going to shit in that class .
eh, nevermind, went and got some help from the professor to clear a lot of things up .
_________________ "Suche gut gebauten Achtzehn- bis Dreißigjährigen zum Schlachten"
Der Metzgermeister
\\GMAN 160GB+ shared
Last edited by Dissension on Mon 10-11-2004 12:07PM, edited 1 time in total.
The day I was gone was the day he talked about random # generators,
you mean dice?
_________________ And the tongue is a flame of fire. It is full of wickedness that can ruin your whole life. It can turn the entire course of your life into a blazing flame of destruction, for it is set on fire by hell itself.
To generate actual numbers, call the function "rand(max)", where "max" is the integer set as the maximum parameter. For a minimum, you'll need to put the "rand" function in a do-while loop until it gives you a value greater than the minimum. The "rand" function is in the <cstdlib> library, so you need to include that, too.
Why not just call rand() and take the result and mod it with your maximum + 1 ?
In other words:
int result;
const int MaximumRandomNumber = 1000; //I made that up, use whatever you're supposed to.
result = rand() % (MaximumRandomNumber + 1);
EDIT: Derf, I'm a tard, that doesn't do what you need.
Scale the limits back to zero. Suppose you want a number between 200 and 800. So, set your maximum for the random generator to 600 (which is 800 minus 200). That'll generate a number between 0 and 600. Then add 200 to that result. The smallest number that rand() would generate is 0. 0 + 200 = 200, your lower limit. The largest number that rand(600) would generate is 600. 600 + 200 = 800, your upper limit.
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum