prng

no cryptography random generator seed allowed in C#?

这一生的挚爱 提交于 2019-12-23 12:48:01
问题 It seems that there is no way to manually seed the RNGCryptoServiceProvider in C#. Is there really nothing simple I can do below to get repeatable randomBytes here for debugging? RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider(); byte[] randomBytes = new byte[20]; rngCsp.GetBytes(randomBytes); MessageBox.Show(Convert.ToBase64String(randomBytes)); I know that I could manually enter the 20 bytes, but this is a pain since I really need many more than 20. Also, I know that I could

ios Swift: looking for a cross compatible method to Java's Random() PRNG that has identical output

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 19:16:57
问题 Here's my delimna: I am writing an application that needs to exactly reproduce the PRNG output from a game that was written in Java that uses the Java random() with a given seed to create all it's initial game 'world' data. The problem I am facing is that Java's random() and ios Swift native PRNG do not generate the same values when given the exact same seeds. Here are my test cases: In all cases the same 'seed' is used, and the formula is for a random Integer between 0 and 9. In Java: import

ios Swift: looking for a cross compatible method to Java's Random() PRNG that has identical output

淺唱寂寞╮ 提交于 2019-12-22 19:14:02
问题 Here's my delimna: I am writing an application that needs to exactly reproduce the PRNG output from a game that was written in Java that uses the Java random() with a given seed to create all it's initial game 'world' data. The problem I am facing is that Java's random() and ios Swift native PRNG do not generate the same values when given the exact same seeds. Here are my test cases: In all cases the same 'seed' is used, and the formula is for a random Integer between 0 and 9. In Java: import

Looking for decent-quality PRNG with only 32 bits of state

孤人 提交于 2019-12-22 17:51:38
问题 I'm trying to implement a tolerable-quality version of the rand_r interface, which has the unfortunate interface requirement that its entire state is stored in a single object of type unsigned , which for my purposes means exactly 32 bits. In addition, I need its output range to be [0,2³¹-1] . The standard solution is using a LCG and dropping the low bit (which has the shortest period), but this still leaves very poor periods for the next few bits. My initial thought was to use two or three

What are good methods for hashing bits in an Int32 or UInt32?

痴心易碎 提交于 2019-12-22 08:24:44
问题 I have an implementation of a pseudo random number generator, specifically of George Marsaglia's XOR-Shift RNG. My implementation is here: FastRandom.cs It turns out that the first random sample is very closely correlated with the seed, which is fairly obvious if you take a look at the Reinitialise(int seed) method. This is bad. My proposed solution is to mix up the bits of the seed as follows: _x = (uint)( (seed * 2147483647) ^ ((seed << 16 | seed >> 48) * 28111) ^ ((seed << 32 | seed >> 32)

Quality of PostgreSQL's random() function?

霸气de小男生 提交于 2019-12-19 19:57:27
问题 Let's say I'm creating a table foo with a column bar that should be a very large random integer. CREATE TABLE foo ( bar bigint DEFAULT round(((9223372036854775807::bigint)::double precision * random())) NOT NULL, baz text ); Is this the best way to do this? Can anyone speak to the quality of PostgreSQL's random() function? Is the multiplication here masking the entropy? Note that I do have good hardware entropy feeding into /dev/random . 回答1: Postgresql random is based on their own portable

Generate Array of Numbers that fit to a Probability Distribution in Ruby?

风流意气都作罢 提交于 2019-12-18 18:01:21
问题 Say I have 100 records, and I want to mock out the created_at date so it fits on some curve. Is there a library to do that, or what formula could I use? I think this is along the same track: Generate Random Numbers with Probabilistic Distribution I don't know much about how they are classified in mathematics, but I'm looking at things like: bell curve logarithmic (typical biology/evolution) curve? ... Just looking for some formulas in code so I can say this: Given 100 records, a timespan of 1

Do PRNG need to be thread safe?

允我心安 提交于 2019-12-14 01:07:01
问题 As long as concurrent calls don't cause seg-v's or return the same value, what reasons are there for preventing race conditions and data corruption in PRNGs when those error's primary effects are unpredictable results and that is the point of a PRNG? Edit: are there any PRNG that wouldn't suffer under race conditions and data corruption? 回答1: PRNGs are meticulously constructed tools -- frankly, if race conditions and threading bugs were a good PRNG, the implementation would be written that

Can two PRNG's produce the same number with different seeds?

狂风中的少年 提交于 2019-12-13 05:59:46
问题 I know if you use the same seed with two different PRNG's you'll receive the same sequence of numbers. Does anyone know if it's possible to generate the same number with two different seeds? If so, what are the odds? I ran a test on this and received some strange results. If I have two instances of the same PRNG and I seed them with two different random seeds each time. The random number has to be between 0 and 1000. I get the same number 1046 times after 10,000,000 iterations. If I don't

Windows-equivalent of POSIX srandom(…) and random() functions?

元气小坏坏 提交于 2019-12-12 14:21:17
问题 I'm trying to port some code over from UNIX to Windows, and I need an implementation of POSIX srandom(x) and random() functions that, for a given seed x , generate the same number sequence as the one that conforms to POSIX.1-2001. What are some of the available options on Windows? 回答1: srandom and family are members of glibc. You can probably copy the source code from glibc for srandom/random into your application, as long as it's license compatible. If you're looking for another