#include "SDL_config.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "SDL_test.h"
void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi, unsigned int ci)
{
if (rndContext==NULL) return;
rndContext->a = 1655692410;
rndContext->x = 30903;
rndContext->c = 0;
if (xi != 0) {
rndContext->x = xi;
}
rndContext->c = ci;
rndContext->ah = rndContext->a >> 16;
rndContext->al = rndContext->a & 65535;
}
void SDLTest_RandomInitTime(SDLTest_RandomContext * rndContext)
{
int a, b;
if (rndContext==NULL) return;
srand((unsigned int)time(NULL));
a=rand();
srand((unsigned int)SDL_GetPerformanceCounter());
b=rand();
SDLTest_RandomInit(rndContext, a, b);
}
unsigned int SDLTest_Random(SDLTest_RandomContext * rndContext)
{
unsigned int xh, xl;
if (rndContext==NULL) return -1;
xh = rndContext->x >> 16;
xl = rndContext->x & 65535;
rndContext->x = rndContext->x * rndContext->a + rndContext->c;
rndContext->c =
xh * rndContext->ah + ((xh * rndContext->al) >> 16) +
((xl * rndContext->ah) >> 16);
if (xl * rndContext->al >= (~rndContext->c + 1))
rndContext->c++;
return (rndContext->x);
}