...

View Full Version : Help (i cant say much more)



schmalx
07-19-2007, 12:25 PM
here is the basics of my code


#include <windows.h>
#include <time.h>

int Chance;
int x;

int compress()
{
if (Chance < 500){
x = 1;
}
else if (Chance < 990){
x = 2;
}
else if (Chance < 997){
x = 3;
}
else if (Chance < 998){
x = 4;
}
else if (Chance <999){
x = 5;
}
else if (Chance == 999){
x = 6;
}

return x;
}
int main()
{
srand(GetTickCount());
for( ; ; )
{
Chance = rand() % 1000;
Sleep(rand() % 60000);

switch(x){
case 1:
bla bla bla
break;
case 2:
bla bla bla
break;
case 3:
bla bla
break;
case 4:
bla bla bla
break;
case 1:
bla bla bla
break;
default case:
bla bla bla
break;
}
}
return 0;
}

my question is will it work and for every loop will it come up with a different number.

also is there an easier way to have events and have there be for example
10% chance event 1 happens
10% chance event 2 happens
20% chance event 3 happens
60% chance event 4 happens

any help is appreciated

oracleguy
07-19-2007, 05:12 PM
Well why don't just compile it and try it? See if it does what you expect?

Also you never set the global variable x and you shouldn't use a for loop like that.

ralph l mayo
07-19-2007, 09:47 PM
There's nothing wrong with using a for loop like that imo. I prefer it to while(1) for event loops, which is basically what this is except it's making up its own events. This will not work as you expect because the stock implementation of rand() has a very short period... it'll cycle through the same set of values again and again, and will only look random on scales shorter than the period. If this is for a game or something that needs to run for a bit with lapsing into predictability you'll need to explore third-party random number libraries or (not recommended) roll your own.

schmalx
07-20-2007, 10:39 AM
Well why don't just compile it and try it? See if it does what you expect?
I didnt have a compiler at the time



Also you never set the global variable x

lol yeah


and you shouldn't use a for loop like that.

why not?


also i made program that will change the colours of all the pixels on the screen to black in a continuous loop.
now i have noticed that if i go to switch user and log back on as the same person the program is still running but it is doing nothing.
why is this?
and how can i stop this from happening?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum