#include <../arch/arch.h>

static LONG call_count = 1;

void	V_CALL
archUniqueString(char *buf,vsize_t buffer_size)
{
	u32_t mask, salt;
	ran_state_t rs;
	DWORD pid = GetCurrentProcessId();
	buf[--buffer_size] = 0;
	/*
	 * call_count must be aligned on 4-byte boundary
	 */
	V_ASSERT(!((unsigned)(&call_count) & 3));
#ifdef MUST_DIE_DEAD
	salt = InterlockedExchangeAdd(&call_count, 1);
#else
	InterlockedIncrement(&call_count);
	salt = call_count;
#endif
	ranInitState(&rs,salt);
	mask = (pid + (pid >> 4) + (pid >> 8) + (pid >> 16)) & 0xF;
	for(;buffer_size;buffer_size--,buf++)
		*buf = nibble2HexChar((u8_t)(ranGenerateNext(&rs) ^ mask));
}
