This is an example of the double-slit R experiment. When x is observed, it acts as a particle; when unobserved it acts as a wave. Behold g <- function(size) { set.seed(1) ; runif(size) } f <- function(x) {set.seed(2) ; x*runif(length(x)) } f2 <- function(x) {print(x); set.seed(2) ; x*runif(length(x)) } f(g(2))...

For the record, a (rather slow) solution as discussed above: public byte[] rand(byte[] seed, int n) { try { byte[] data = null; ByteArrayOutputStream ret = new ByteArrayOutputStream(n); while (ret.size() < n) { MessageDigest md = MessageDigest.getInstance("SHA1"); md.update(seed); if (data != null) md.update(data); data = md.digest(); ret.write(data, 0, Math.min(n -...

Just use a hash function. A classic is hash_pjw, unsigned hash_pjw (const void *str) { const char *s = str; unsigned int g, h = 1234567u; while (*s != 0) { h = (h << 4) + *s++; if ((g = h & (unsigned int) 0xf0000000) != 0) h =...

Random number generator in cmd uses the current time (with second resolution) to seed the prng. This initialization is done once per cmd instance. So, if you are running your batch file in a new cmd instance each time, the seed is very similar in each case. But if you...

search,random,sphinx,random-seed

As far as I'm aware Sphinx added rand_seed option just a while ago that may serve your purpose. http://sphinxsearch.com/docs/current/sphinxql-select.html Mind you, it'll be only in the one of the newer builds of Sphinx....

You can workaround your issue by always reinitializing the srand with the last random number generated. You "mix up" the seeds but you still have a reproducable way to generate random numbers. Here is some code : function getNextRandomNumber() { $mySeed = 0; // a default seed value if (isset($_SESSION['seed']))...

java,random,javacard,random-seed

setSeed() supplements rather than replaces the seed for a Java Card RandomData object, just like SecureRandom on Java SE. This is however not made explicit in the API up to 3.0.4. However, if you read the text of the constant ALG_PSEUDO_RANDOM you'll get: Utility pseudo-random number generation algorithms. The random...

From the Mathworks documentation, you can use rng('shuffle'); before calling rand to set a "random" seed (based on the current time). Setting the seed manually (either by not changing the seed at startup, by resetting using rng('default'), or setting the seed manually by rng(number)) allows you to exactly repeat previous...

c,random,codeblocks,random-seed

You are assigning sum before setting num1 and num2. Move the sum = num1 + num2; line into the loop after the num2 = rand()%maxNumber; line and it should work correctly. There are some other errors as well (such as initializing i with 0). BTW, it is generally considered a...

python,random,cryptography,random-seed

Follow da code. To see where the random module "lives" in your system, you can just do in a terminal: >>> import random >>> random.__file__ '/usr/lib/python2.7/random.pyc' That gives you the path to the .pyc ("compiled") file, which is usually located side by side to the original .py where readable code...

python,numpy,random,random-seed

When I don't want an upper bound I'll often use sys.maxint for the upper bound as an approximation

javascript,random,sin,random-seed

So, I looked at your method, t1wc, and I found that it isn't actually evenly distributed. It is significantly more likely to spit out numbers near 0 or near 1 than it is to spit out numbers near 0.5, for example. This is just a consequence of the way that...

No, setting either the seed or the state is sufficient: import random # set seed and get state random.seed(0) orig_state = random.getstate() print random.random() # 0.8444218515250481 # change the RNG seed random.seed(1) print random.random() # 0.13436424411240122 # setting the seed back to 0 resets the RNG back to the original...

python,python-3.x,hash,python-3.3,random-seed

In Python 3.3, the hash seed is not cryptographically strong; it is generated at startup with the following pseudo-random generator: /* Fill buffer with pseudo-random bytes generated by a linear congruent generator (LCG): x(n+1) = (x(n) * 214013 + 2531011) % 2^32 Use bits 23..16 of x(n) to generate a...

java,arrays,random,int,random-seed

You don't assign a Random to an int -- you need to call nextInt, passing a int that gives the range between 0 and that bound minus 1. a[i] = ran1.nextInt(10); // 0-9 or substitute what you want for 10 ...

Simply use set.seed just before you create index: > set.seed(1) > index <- sample(7009728, 50000) > head(index) [1] 1861144 2608487 4015546 6366287 1413735 6297463 It sets random number generator seed and ensure consistent results. ...

c++,c++11,random,random-seed,mersenne-twister

Let's recap (comments too), we want to generate different seeds to get independent sequences of random numbers in each of the following occurrences: The program is relaunched on the same machine later, Two threads are launched on the same machine at the same time, The program is launched on two...

The only real benefit of a seed is that your results are reproducible. Ranges of seeds (at least as far as I know) aren't likely to be skewed in one direction more than any other, they just provide a concrete seed for the pseudo random generator rather than to use...

I thought it would be nice to have just an independent RNG inside your function, that is not affected by the global seed, but would have its own seed. Turns out, randtoolbox offers this functionality: library(randtoolbox) replicate(3, { set.seed(1) c(runif(1), WELL(3), runif(1)) }) # [,1] [,2] [,3] #[1,] 0.265508663 0.2655087...

Assuming you're not interested in retaining the seed_seq instance used for constructing the mt19937, you could do something like this: struct foo { std::mt19937 mt; std::normal_distribution<> ndist; std::function<decltype(mt)::result_type()> rng_normal; foo() : mt{make_mersenne_twister()} , rng_normal{std::bind(ndist, std::ref(mt))} {} static std::mt19937 make_mersenne_twister() { std::minstd_rand seed_rng(std::random_device{}()); // random seed std::vector<int> seeds(16); std::generate(seeds.begin(), seeds.end(), seed_rng);...

python,numpy,random,scikit-learn,random-seed

Should I use np.random.seed or random.seed? That depends on whether in your code you are using numpy's random number generator or the one in random. The random number generators in numpy.random and random have totally separate internal states, so numpy.random.seed() will not affect the random sequences produced by random.random(),...