13 votes

How do I reliably generate random numbers in Python distributed across multiple nodes?

To the best of my knowledge, Numpy does not support independent streams. Indeed, getting independent streams from the Mersenne Twister (Pythons RNG) is notoriously difficult although it can be done. ...
LKlevin's user avatar
  • 2,493
10 votes
Accepted

Parallel Mersenne Twister for Monte Carlo

Like you say, using the Mersenne Twister for parallel computations is almost always done incorrectly, as the correct method is tricky to implement. By far the easiest and best answer would be to move ...
LKlevin's user avatar
  • 2,493
8 votes
Accepted

What PRNG function is this?

A little playing with the sequence of numbers generated by the C code shows that the sequence is $z_{i+1}=5z_{i}+273 \mod 2^{16}$ This is a linear congruential generator (LCG). It's easy to show ...
Brian Borchers's user avatar
6 votes

How to traverse $\{0, 1, \dots, 2^n-1\}$ in random order?

A random number generator will give you random numbers that you can tweak to be between zero and 2^n and consequently it will allow you to sample random locations ...
Wolfgang Bangerth's user avatar
5 votes

How do I reliably generate random numbers in Python distributed across multiple nodes?

It is not a problem if one processor generates a number that has already appeared on a different processor. It would, however, be a problem if the two generated whole sequences that are similar. This ...
Wolfgang Bangerth's user avatar
4 votes

Simple Monte Carlo in C++, result dependent from seed

As noted in the comments by Kirill, the y-axes of the two plots are very different. And if they are rescaled accordingly, the boxes will certainly look very similar, if not identical. Therefore, it ...
Anton Menshov's user avatar
  • 8,652
4 votes
Accepted

Running a Random Number generator in parallel? Will this speed up a computation?

The random number generator is rarely the limiting factor in computational science. RNGs are usually quite simple and fast, a few dozen instructions, really. If you are doing anything even remotely ...
Wolfgang Bangerth's user avatar
3 votes

Parallel Mersenne Twister for Monte Carlo

If you want to use MT, you can use SFMT as your PRNG and SFMT jump to generate multiple streams. You can simply initialise MT with one seed, and then jump ahead by e.g. $1 \cdot 10^{60}$, $2 \cdot 10^...
Jukka Suomela's user avatar
3 votes

How good are current implementations of rand() in C?

But these seem pretty old criticisms of the rand function This may be a nitpick, but I want to point out what I think is a flaw in this logic. Compilers are often extremely conservative about ...
Kirill's user avatar
  • 11.4k
3 votes

Producing random variables with exp. distribution, but I need to use a constant! (python)

The inverse transform sampling method is generally used to allow sampling uniform random variables and then transforming them such that the result has the suitable distribution. To do this you need an ...
user9794's user avatar
  • 465
2 votes

Difference between true & pseudo random numbers

Most random numbers are in fact pseudo-random: they use a seed that is fed to a perfectly deterministic algorithm which can then generate series of numbers which are periodic but with a very large and ...
Silmathoron's user avatar
2 votes
Accepted

Generate Random Number outside Bounds:

For the sake of your example, let's say RAND_MAX=12 and i=17. Then do the following procedure: Choose two random numbers $r_1,r_2$ and combine them to a single random number uniformly distributed in $[...
Wolfgang Bangerth's user avatar
2 votes

Generate Random Number outside Bounds:

Instead of fixing the provided generator use a reasonable modern choice. It will be faster and have better statistical quality. Possible examples include the various variants of xorshift+, xorshift* ...
MB Reynolds's user avatar
2 votes

How to evaluate "quality" of set of attainable random permutations

To permute a list, there is no need to enumerate the n! possibilities. Shuffling the list should be sufficient. Pseudo code (from wiki article) for shuffling would be ...
bernie's user avatar
  • 165
2 votes

How to evaluate "quality" of set of attainable random permutations

You can do some spot checking. Testing for all $n!$ possibilities is impractical, but you can make some unit tests to make sure that after doing sufficiently many shuffles certain properties of the ...
Chris Rackauckas's user avatar
2 votes

How to generate Poisson-distributed random numbers quickly and accurately?

If you can use C++11 you can use the built-in Poisson distribution ...
Henri Menke's user avatar
2 votes

Is there a better way to do run time analysis than this?

Welcome to SE SciComp. First of all, I would suggest using Jupyter so that you have access to IPython and its nice timing magics (see %time and %timeit magic function). These magics take into account ...
GertVdE's user avatar
  • 6,179
2 votes

How to plot random points in 3 dimensions in order to calculate volume of a torus through Monte Carlo integration

You don't need to plot a torus to calculate its volume. Moreover you can analytically compute the volume integral and it's even on wikipedia. With Monte Carlo you can use rejection sampling to figure ...
lightxbulb's user avatar
  • 1,914
1 vote
Accepted

Introductory reference on bit-twiddling?

Bit-twiddling is sometimes used as part of the numerical algorithms that are apropos for this site (e.g., hardware implementations of the Fast Fourier Transform, simulation of quantum computers, etc.)....
Juan M. Bello-Rivas's user avatar
1 vote
Accepted

Why does this line of code give a flat distribution?

You are omitting to mention what GRNDM actually does (and that turns out to be not so obvious to find on the internet): It returns random numbers in the interval $[...
Wolfgang Bangerth's user avatar
1 vote

How good are current implementations of rand() in C?

Though the question is about C, I still consider the following information regarding C++11 relevant. In C++11, <random> was added that is both designed to fix ...
Anton Menshov's user avatar
  • 8,652
1 vote

Weighted Monte Carlo Integration

What about dividing the interval $[0,0.6]$ in sub-intervals $[x_i,x_{i-1}]$ so that in each one the function value has the same order of magnitude? For example you could choose $x_0 =0$, $x_{m}=0.6$ $$...
Gabriele's user avatar
  • 173
1 vote

How to traverse $\{0, 1, \dots, 2^n-1\}$ in random order?

Use a trivial $n$-bit counter, and encrypt it using a block cipher in any configuration other than ECB or CTR, starting with the least-significant bits as your first block so the small change ...
sh1's user avatar
  • 141
1 vote

Why my linear congruential generator generate low quality random numbers?

This is simply how LCG works. You can reduce the problem for your application by simply exclusive-or-ing some of the high bits over some of the low bits in the output (but do not use this modified ...
sh1's user avatar
  • 141
1 vote

Implementation of stochastic cellular automata

Not sure if I understood correctly, but I think that if your parameters µ and $\Delta t$ are constant during all the simulations and for all nodes, you can generate ...
ZiGaelle's user avatar
  • 121
1 vote

How to generate Poisson-distributed random numbers quickly and accurately?

I found the answer from the book Numerical Recipes in C, but unfortunately the code in that book is copyrighted. So, I re-derived a similar code that is slightly different but does the same thing. ...
juhist's user avatar
  • 151
1 vote
Accepted

Generate a set of random x,y,z numbers, with a minimum difference between them, between defined limits

So one thing you can do is implicitly represent a structured region, like a 3D rectangular volume, as a set of chopped up sub-volumes where each sub-volume automatically enforces the spatial ...
spektr's user avatar
  • 4,228
1 vote
Accepted

Using physical parameter as a Gaussian random variable in a simple Poisson problem

In the loop over your instances of 100 random values for $k$, you could write the value for $k$ into a file, and call your finite element code; the finite element code could then open the file, read ...
Wolfgang Bangerth's user avatar
1 vote

How do I reliably generate random numbers in Python distributed across multiple nodes?

This exact problem (not generating the same random number sequences) is described in John D. Cook's blog post Random number generator seed mistakes. The solution is simply to ensure that processes ...
mortenvp's user avatar
  • 111
1 vote
Accepted

Pseudo random numbers

Psudorandom numbers generated via methods like LCG are generated via a discrete dynamical system (i.e. a system where $x_n = f(x_{n-1})$). For these types of systems, tools such as Ergodic Theory can ...
Chris Rackauckas's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible