#include "defs.h"

//Translated/rewritten by SL, March 3-4 2005
//This is designed to generate the same results as BC 3.1's random number generator.

Uword rand_count;
Uword rand_seed;

void my_srand(Uword seed) {
	rand_count = 0;
	rand_seed = seed;
}

Word my_rand() {
	Uword result = rand_seed * 0x15a;	//we discard the high 2 bytes
	if (rand_count!=0) {
		result = rand_count * 0x4e35 + result;
	}
	Udword result2 = ((Udword)rand_seed)*0x4e35;
	result2+=((Udword)result)<<16;
	result2++;
	rand_count=(result2>>16)&0xFFFF;
	rand_seed=result2&0xFFFF;
	return rand_count&0x7FFF;
}
