Exemple #1
0
void *create_randomness(uint64_t n, std::vector<T> &rand) {
	// Prepare n bits of randomness using a pseudo-random number generator.
	// A vector instead of a raw array is used to store the data because
	// this way, it's easier for the caller to keep track of the allocation.
	std::uniform_int_distribution<T>
		distribution(0, std::numeric_limits<T>::max());
	std::mt19937 mt_engine(42);
	auto generator = std::bind(distribution, mt_engine);
	
	uint64_t num_chunks = n/sizeof(rand[0])+1;
	rand.reserve(num_chunks);
	
	for (auto i = 0; i < num_chunks; i++) {
		rand[i] = generator(); 
	}

	return (&rand[0]);
}
		void GLLensDustFilter::UpdateNoise() {
			SPADES_MARK_FUNCTION();
			
			noise.resize(128 * 128);
			uint32_t rnd = mt_engine();
			rnd ^= 0x7abd4513;
			for(size_t i = 0; i < 128 * 128; i++) {
				noise[i] = rnd;
				
				rnd = (rnd * 0x71931) + 0x981f311;
				if(rnd == 0xffffffff) // mod 2^32-1
					rnd = 0;
			}
			
			IGLDevice *dev = renderer->GetGLDevice();
			dev->BindTexture(IGLDevice::Texture2D, noiseTex);
			dev->TexSubImage2D(IGLDevice::Texture2D,
							   0, 0, 0, 128, 128,
							   IGLDevice::BGRA, IGLDevice::UnsignedByte,
							   noise.data());
		}