Example #1
0
void cryptoRandom (int iCount, CIPInteger *retx)

//	cryptoRandom
//
//	Generate iCount BYTEs of randomness

	{
	//	Edge cases

	if (iCount == 0)
		*retx = CIPInteger();

	//	Generate bytes

	CBuffer Chaos(iCount);

	int iLeft = iCount;
	while (iLeft)
		{
		//	rand_s is Window's cryptographic random number generator.
		//	NOTE: rand_s IS thread-safe, since it just calls an internal OS
		//	function.

		unsigned int dwRnd;
		rand_s(&dwRnd);

		int iWrite = Min(iLeft, (int)sizeof(DWORD));
		Chaos.Write(&dwRnd, iWrite);

		iLeft -= iWrite;
		}

	//	Initialize. Note that CIPInteger expects the byte stream to be in big-
	//	endian order, but since random is random it doesn't matter that we're
	//	backwards.

	retx->InitFromBytes(Chaos);
	}
Example #2
0
/*
 * Apply a "mount" texture.
 */
void
MountApply(
    Mount               *mount,
    Geom                * /*prim*/,
    Ray                 * /*ray*/,
    Vector              *pos,
    Vector              *norm,
    Vector              * /*gnorm*/,
    Surface             *surf)
{
	int index;
	Float t;

	t = Chaos(pos, 7);
	index = (int)(pos->z + mount->turb*t - mount->slope*(1.-norm->z))*256;
	if (index < 0)
		index = 0;
	if (index > 255)
		index = 255;

	ColorMultiply(surf->amb, mount->cmap[index], &surf->amb);
	ColorMultiply(surf->diff, mount->cmap[index], &surf->diff);
	ColorMultiply(surf->spec, mount->cmap[index], &surf->spec);
}