#include <v_lib.h>
#include "ljutil.h"

vec_t frand(vec_t min,vec_t max)
{
	if(!IsZero(max-min))
		return min + ((vec_t)(rand() >> 2) / (vec_t)(RAND_MAX >> 2)) * (max-min);
	else
		return min;
}

void vec3Rand(vec3_t vec3_ret,vec_t min,vec_t max)
{
	vec3_ret[0] = frand(min,max);
	vec3_ret[1] = frand(min,max);
	vec3_ret[2] = frand(min,max);
}

void spin_lock(spinlock_t *lock)
{
	while(*lock)
		schedYield();
	(*lock)++;
}

void spin_unlock(spinlock_t *lock)
{
	(*lock)--;
}

extern int seed;

int ljutil_init(void)
{
	if(seed == -1)
		seed = timeTickCount();
	srand(seed);
	return 0;
}
