prng

Why does this random() distribution look asymmetric?

不想你离开。 提交于 2019-12-07 02:28:59
问题 Edit: This is using Google Chrome 36 I was messing around with html5 canvas, generating points randomly distributed inside a cube and projecting that onto a 2D canvas. Surprisingly, the results don't look very symmetric at all, and I suspect that Javascript's Math.random() is letting me down. Can anyone tell me why this is happening? Is it possible to make it actually look random, without making it slower? var ctx = canvas.getContext('2d'); for (var i = 0; i < 10000000; i++) { var x = Math

How to seed the PRNG for BN_generate_prime

◇◆丶佛笑我妖孽 提交于 2019-12-06 03:45:39
问题 I have not been able to find an answer as to what is used to generate the primes with BN_generate_prime in openssl/bn.h. Also, how would I seed whatever PRNG that this function uses? Separate question but relevant to my code (I'm writing a program to generate RSA key pairs): how would I check if the high order bit is set in a BIGNUM? Say I generate a 512 bit prime. Would I use BN_is_bit_set(prime, 512)? Thanks 回答1: BN_generate_prime is a deprecated function, says here. Also, it is defined in

I need a portable, consistent pseudorandom number generator

↘锁芯ラ 提交于 2019-12-06 02:47:29
问题 I am writing a kid sister encryption function and I need a PRNG that produces consistent results across OSes (so no floating point math, taking advantage of hardware, or system level software). It would be nice, but not necessary, for the PRNG had a period longer than 2 30 . I am currently using a 32 bit Xorshift: #!/usr/bin/perl use strict; use warnings; { use integer; #use integer math my $x = 123456789; my $y = 362436069; my $w = 88675123; my $z = 521288629; sub set_random_seed { $w =

What is the difference between using std::random_device with pRNG e.g. std::mt19937 and without?

蹲街弑〆低调 提交于 2019-12-05 19:26:00
In C++11 one can generate numbers with the use of std::random_device with or without a pseudo random number generator like mt19937. What will be the difference using this in this exemplar code: #include <random> #include <iostream> int main() { std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<double> dist(1, 10); for (int i=0; i<16; ++i) std::cout << dist(rd) << "\t" << dist(mt) << "\n"; } std::random_device is supposed to get you a seed for engines like mt19937 . The quality of successive numbers produced is completely undefined and may easily be insufficient for

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

狂风中的少年 提交于 2019-12-05 12:28:10
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) * 69001) ^ ((seed << 48 | seed >> 16) * 45083)); So I have significantly weakened any correlation by

Random access encryption with AES In Counter mode using Fortuna PRNG:

人走茶凉 提交于 2019-12-05 11:34:53
I'm building file-encryption based on AES that have to be able to work in random-access mode (accesing any part of the file). AES in Counter for example can be used, but it is well known that we need an unique sequence never used twice. Is it ok to use a simplified Fortuna PRNG in this case (encrypting a counter with a randomly chosen unique key specific to the particular file)? Are there weak points in this approach? So encryption/decryption can look like this Encryption of a block at Offset: rndsubseq = AESEnc(Offset, FileUniqueKey) xoredplaintext = plaintext xor rndsubseq ciphertext =

Is PHP's rand function really so bad? [closed]

左心房为你撑大大i 提交于 2019-12-05 01:10:42
I know that it is encouraged to use mt_rand() over rand() because it uses the Mersenne Twister over whatever PRNG rand() uses, but here's something that never seems to be factored in: user activity. In fact, the actions of users can be considered pretty random. For instance, at any given moment, there might be a 4% chance a user might trigger a rand() call for one feature, an 8% chance of a user triggering three rand() calls and a shuffle() , a 20% of a user triggering two rand() calls, and every time a user loads a page the PRNG advances by one. After all, isn't NPC movement what makes RNG

Is it possible to reverse a pseudo random number generator?

血红的双手。 提交于 2019-12-04 18:55:31
问题 Is it possible to reverse a pseudo random number generator? For example, take an array of generated numbers and get the original seed. If so, how would this be implemented? 回答1: This is absolutely possible - you just have to create a PRNG which suits your purposes. It depends on exactly what you need to accomplish - I'd be happy to offer more advice if you describe your situation in more detail. For general background, here are some resources for inverting a Linear Congruential Generator:

Getting a random real number in a certain range using WELL512

我们两清 提交于 2019-12-04 09:37:51
I'm using the WELL512 pseudorandom number generator function described in this paper . The function returns a random unsigned long value. How do I use this return value to produce a random real number within a certain range - like a float between 340.92491 and 859812.53198 inclusive. The documentation for the C rand() function seems to warn against using mod. Nemo Well, mathematically it's just: min_value + (max_value - min_value) * (my_random() / (long double)ULONG_MAX) (Assuming my_random() returns a uniformly distributed number between 0 and ULONG_MAX) However, depending on the exact values

I need a portable, consistent pseudorandom number generator

我的梦境 提交于 2019-12-04 07:08:43
I am writing a kid sister encryption function and I need a PRNG that produces consistent results across OSes (so no floating point math, taking advantage of hardware, or system level software). It would be nice, but not necessary, for the PRNG had a period longer than 2 30 . I am currently using a 32 bit Xorshift : #!/usr/bin/perl use strict; use warnings; { use integer; #use integer math my $x = 123456789; my $y = 362436069; my $w = 88675123; my $z = 521288629; sub set_random_seed { $w = shift; } sub random { my $t = $x ^ ($x << 11); $x = $y; $y = $z; $z = $w; my $rand = $w = ($w ^ ($w >> 19)