Irbyz/aftershock-xe

coinflip is not random

Closed this issue · 2 comments

Irbyz commented

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

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;
}

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