Irbyz / aftershock-xe

AfterShock XE is a fork of the AfterShock mod for OpenArena FPS game.
https://discord.gg/fd79Ktf
GNU General Public License v2.0
12 stars 8 forks source link

coinflip is not random #147

Closed Irbyz closed 3 years ago

Irbyz commented 5 years ago

There's a problem with coinflip currently. Most of the time it takes turns showing heads and tails if you use the command in succession: shot0354

sago007 commented 5 years ago

I had the same problem in baseoa. The result from the rand function needs to be shifted 1 bit, as the last bit always flips.

I ended up using the values from the C reference implementation instead:

static unsigned int randSeed = 0;

void srand(unsigned seed) {
    randSeed = seed;
}

int rand(void) {
    randSeed = (1103515245 * randSeed + 12345) ;
    return (randSeed>>16) & RAND_MAX;
}
dedavidd commented 5 years ago

it seems that the rand function is based on eventnumber. with <<1 it now does heads heads, tails tails, heads heads tails tails, etc gonna change to your more complex suggestion