prng

Equivalent of /dev/urandom on Windows?

允我心安 提交于 2019-11-30 12:07:06
My application would like to get a random number, preferably with entropy if available, but does not need cryptographic quality, and would like to do ensure that the call does not block if the system entropy pool is depleted (e.g. on a server in a farm). I am aware of CryptGenRandom ( http://msdn.microsoft.com/en-us/library/windows/desktop/aa379942(v=vs.85).aspx ), but its behaviour with respect to blocking under adverse entropy conditions is not specified. On Unix, /dev/urandom supports this use case. Is there equivalent functionality available on Windows? I would prefer to avoid using a non

Lua 4.0 random number generator

落爺英雄遲暮 提交于 2019-11-30 09:50:11
问题 I don't have access to random() in Lua 4.0 (DON'T ASK), so I need to roll my own random number generator. Or rather I have to roll another one since the one I implemented several years ago is failing me now. I.e. I am noticing repeating values which is bad. Any suggestions or examples written in Lua that I can use? FYI here's the one I've been using up until now: seedobja = 1103515245 seedobjc = 12345 seedobjm = 4294967295 --0x100000000 function srandom(seedobj, fVal1, fVal2) seedobj[1] = mod

Picking A, C and M for Linear congruential generator

别说谁变了你拦得住时间么 提交于 2019-11-30 08:36:05
I am looking to implement a simple pseudorandom number generator (PRNG) that has a specified period and guaranteed no collisions for the duration of that period. After doing some research I came across the very famous LCG which is perfect. The problem is, I am having trouble understanding how to properly configure it. Here is my current implementation: function LCG (state) { var a = ?; var c = ?; var m = ?; return (a * state + c) % m; } It says that in order to have a full period for all seed values the following conditions must be met: c and m are relatively prime a-1 is divisible by all

Distributions and internal state

感情迁移 提交于 2019-11-30 03:19:06
On Stackoverflow there are many questions about generating uniformly distributed integers from a-priory unknown ranges. E.g. C++11 Generating random numbers from frequently changing range Vary range of uniform_int_distribution The typical solution is something like: inline std::mt19937 &engine() { thread_local std::mt19937 eng; return eng; } int get_int_from_range(int from, int to) { std::uniform_int_distribution<int> dist(from, to); return dist(engine()); } Given that a distribution should be a lightweight object and there aren't performance concerns recreating it multiple times, it seems

What's the origin of this GLSL rand() one-liner?

≯℡__Kan透↙ 提交于 2019-11-29 19:04:24
I've seen this pseudo-random number generator for use in shaders referred to here and there around the web : float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } It's variously called "canonical", or "a one-liner I found on the web somewhere". What's the origin of this function? Are the constant values as arbitrary as they seem or is there some art to their selection? Is there any discussion of the merits of this function? EDIT: The oldest reference to this function that I've come across is this archive from Feb '08 , the original page now being gone from

Equivalent of /dev/urandom on Windows?

℡╲_俬逩灬. 提交于 2019-11-29 17:50:17
问题 My application would like to get a random number, preferably with entropy if available, but does not need cryptographic quality, and would like to do ensure that the call does not block if the system entropy pool is depleted (e.g. on a server in a farm). I am aware of CryptGenRandom (http://msdn.microsoft.com/en-us/library/windows/desktop/aa379942(v=vs.85).aspx), but its behaviour with respect to blocking under adverse entropy conditions is not specified. On Unix, /dev/urandom supports this

Cryptographically secure unique id

别说谁变了你拦得住时间么 提交于 2019-11-29 17:22:22
问题 I want to generate cryptographically secure unique uuids using php. uniqid() provides unique but not secure ids and openssl_random_pseudo_bytes() provides secure but not unique ids. Is the combination of the two(following code) a proper approach or is there a better solution? uniqid(bin2hex(openssl_random_pseudo_bytes(10)), true); 回答1: I want to generate cryptographically secure unique uuids using php. Okay, that's easily done. uniqid() provides unique but not secure ids and openssl_random

Lua 4.0 random number generator

十年热恋 提交于 2019-11-29 17:07:56
I don't have access to random() in Lua 4.0 (DON'T ASK), so I need to roll my own random number generator. Or rather I have to roll another one since the one I implemented several years ago is failing me now. I.e. I am noticing repeating values which is bad. Any suggestions or examples written in Lua that I can use? FYI here's the one I've been using up until now: seedobja = 1103515245 seedobjc = 12345 seedobjm = 4294967295 --0x100000000 function srandom(seedobj, fVal1, fVal2) seedobj[1] = mod(seedobj[1] * seedobja + seedobjc, seedobjm) local temp_rand = seedobj[1] / (seedobjm - 1) if (fVal2)

Distributions and internal state

笑着哭i 提交于 2019-11-29 00:59:44
问题 On Stackoverflow there are many questions about generating uniformly distributed integers from a-priory unknown ranges. E.g. C++11 Generating random numbers from frequently changing range Vary range of uniform_int_distribution The typical solution is something like: inline std::mt19937 &engine() { thread_local std::mt19937 eng; return eng; } int get_int_from_range(int from, int to) { std::uniform_int_distribution<int> dist(from, to); return dist(engine()); } Given that a distribution should

differences between random and urandom

与世无争的帅哥 提交于 2019-11-28 17:11:17
I'm trying to find out the differences between /dev/random and /dev/urandom files What are the differences between /dev/random and /dev/urandom ? When should I use them? when should I not use them? Using /dev/random may require waiting for the result as it uses so-called entropy pool , where random data may not be available at the moment. /dev/urandom returns as many bytes as user requested and thus it is less random than /dev/random . As can be read from the man page: random When read, the /dev/random device will only return random bytes within the estimated number of bits of noise in the