Skip to main content
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
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,742
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

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.5k
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
  • 485
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

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
  • 161
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
  • 2,882
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,199
1 vote
Accepted

Random access (quasi-?)random sequence

There's a paper by Gruenschloss about enumerating Sobol points falling within some elementary intervals: https://github.com/lgruen/sample-enum This is used in pbrt with the global sampler in order to ...
1 vote
Accepted

Which type of RNG can I use together with a MT RNG in a simulation?

Maybe I've found a solution myself, hope that someone knowledgable can check if this is correct! I can use a second MT19937 with the same seed where I jump ahead the state of the generator at the ...
Tortar's user avatar
  • 111
1 vote
Accepted

Trying to do a 2D random walk for a particle

You are only moving in one direction for each axis. ...
CLP's user avatar
  • 68
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,742
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
  • 131
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,338
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

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