# Questions tagged [random-number-generation]

Questions on the algorithms for and uses of (pseudo)random number generators in scientific computing.

60 questions
Filter by
Sorted by
Tagged with
44 views

### Numpy random generator seed choice

I am new to understanding pseudorandom number generators and sometimes feel daunted by them. For some time I have used the following approach in my work: In one file, I'd have ...
106 views

### Trying to do a 2D random walk for a particle

I am trying to perform a two-dimensional random walk for a particle, but I am not getting the desired result. The plot produced is a linear plot, which obviously should not have been. Similar code for ...
1 vote
61 views

### Applications where random number generation is a speed bottleneck

Pseudorandom numbers are used massively in Monte Carlo methods, e.g. in physics simulations. The fastest random number generators, such as the xoroshiro or xorshiro families by Vigna (see eg here) are ...
69 views

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

I'm calculating basically a multidimensional random walk problem. To get more accuracy, I need larger systems (more dimensions), which requires longer time. To speed up the calculation, I'm delving ...
1 vote
43 views

### Introductory reference on bit-twiddling? [closed]

I'm looking for introductory resources--web pages, book chapters, articles--that introduce the C language with an immediate focus on bit-twiddling functions (e.g. bitwise XOR, AND, shifts), and of ...
46 views

### How to limit the output value of an Linear Congruential Generator, but still maintain an extremely long period?

Let us suppose that I have a full cycle LCG, following the standard equation Hence, as it has a full cycle, it will have a period of m, and will output values ranging from 0 to m. However, I want to ...
76 views

### Create random number generator from a top hat distribution

How would I use a random number generator to give random numbers from a top hat distribution in Fortran? I've seen lots of information about how to make a Gaussian random number generator, but not one ...
122 views

### Whi are chi-squared distributions in (C++) boost::random and C++ STL faster than in boost::math?

I am trying to generate random chi-squared numbers in C++, according to some degree of freedom (which can be a float). Several libraries can be used for that purpose, among which the C++11 Standard ...
44 views

### Why does this line of code give a flat distribution?

I'm struggling to understand a line of FORTRAN code and was hoping someone on here would be able to help me out. These lines of code are meant to generate a flat distribution - I understand that GRNDM(...
39 views

### Why I am not able to generate Levy distribution using inverse transform method on MATLAB?

I am trying to generate random numbers using Levy distribution in MATLAB. I am using the inverse transform method to generate random numbers and then plot its histogram for pdf estimation. Then I ...
1 vote
66 views

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

I currently have 2 different functions with options to vectorise them: acc_rej_sine(max_iter, algorithm=None) and ...
913 views

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

There is a lot of literature that indicates using rand() for simulations might be harmful. A couple of them are as follows: https://www.sciencedirect.com/science/...
1 vote
156 views

### Weighted Monte Carlo Integration

I have a function $F(x)$ which drops exponentially (like differential QCD cross section vs. Invariant mass). I want to perform Monte-Carlo integration. The problem is that only small $x$'s which have ...
193 views

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

I implemented as an exercise a program to sample the statistics of the escape time of a Brownian particle in a potential well. I used the Euler-Maruyama method to numerically integrate the ...
1 vote
170 views

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

Here, $n$ could be a few hundreds, or even thousands, so it is not possible to pregenerate a list of $$\{0, 1, \dots, 2^n-1\}$$ and shuffle it. Because it is traversal, no number should be visited ...
496 views

### Why my linear congruential generator generate low quality random numbers?

I am implementing an arbitrary bits random number generator (in [$0,2^n$)) and also want to ensure that the generator always generate unique numbers until all possible numbers generated, so I ...
51 views

### Implementation of stochastic cellular automata

In my problem, I have a lattice with a stochastic cellular automaton. In order to simplify a bit, let's say it is 1D. In my system, each node can be type A, B or C. A way to represent the system and ...
4k views

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

I have attempted to create Poisson-distributed random numbers, seeing that it is not so easy as the simple multiplicative algorithm works accurately only if the mean is less than 500. Using logarithms ...
1 vote
60 views

### Random Number Generation-full period

How can i demonstrate that a LCG has full period? Is there a way to demonstrate it or do I just need to check the parameters(a, c, m)?
96 views

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

So I am trying a molecular dynamics simulation, and trying to populate a 3D rectangular volume with random particles which are uniformly distributed throughout the volume. Each molecule has a fixed ...
68 views

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

I want to vary the input parameter of a physical dynamic mechanics problem, as a Gaussian Random variable and view the resulting Probability Density Function (PDF). I used the Finite Element Method to ...
2k views

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

Consider the following scenario: I want to perform a large Monte Carlo simulation across a compute cluster with several nodes. To avoid excessive transmission of data, I am going to generate random ...
1 vote
137 views

### Generate gaussian random field in spherical polar coordinates

I would like to generate an isotropic gaussian random field described by a power spectrum $P(k)$ on a 3D grid which represents spherical polar coordinates (i.e., the angular separation between pixels ...
89 views

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

To randomly permute a list one has to select one of $n!$ possibilities, which quickly goes outside of the capabilities of conventional PRNGs. Even Mersenne Twister fails with a list of length greater ...
1 vote
85 views

### RNG float range for metropolis monte carlo

I have a robust RNG that generates random 32-bit (unsigned) ints. As is probably well known, for metropolis MC simulation, a random number between 0 and 1 is needed to determine acceptance/rejection ...
1 vote
83 views

### Pseudo random numbers

I am learning how to use pseudo random number generators but the instructor just told us how they work without explaining why they work. For example, can one prove that the numbers generated by LCG ...
166 views

### What PRNG function is this?

This is a 16-bit PRNG function, transcribed from assembly to C for easier reading: ...
2k views

### Parallel Mersenne Twister for Monte Carlo

Recently, I came across a comment claiming that almost all researchers doing Monte Carlo methods are doing it wrong. It went on to elaborate that merely choosing different seeds for different ...
2k views

### Difference between true & pseudo random numbers

I recently heard that in Linux, /dev/random and /dev/urandom are pseudo random number generators but not true random number ...
1 vote
102 views

### PETCs - How should one initialize PetscRandom?

The documentation of PETSc shows an example of usage: ...
125 views

### PETSc - how computing a random number between 0 and 1?

In PETSc, I need to generate a random number between 1 and 0. With the include cstdlib, the classical trick is: ...
1 vote
892 views

### Generating Random Numbers in Fortran for Metropolis method

I am having a really hard time getting any kind of reliable / consistent result from my Metropolis code. I have torn it apart and am now examining just the randomness in my random number generator. I ...
1 vote
93 views

135 views

### Multiple independent random number streams

Having multiple streams of pseudo-random numbers known to be independent and with a uniform distribution I want to do Monte Carlo simulations in parallel. In other words, one thread will have a full-...
1k views

### Hashing algorithms/implementations for Monte Carlo simulation

To summarise this question in advance, I'm looking for a good hash function that is suitable for generating pseudo-random numbers in Monte Carlo simulations. This means it should be reasonably fast (...
699 views

### Generating pseudo-random orthonormal bases for random projection

I am performing series of random projections i.e. projecting the input matrix onto randomly generated orthonormal bases (of much lower dimensionality). The projection is just a matrix multiplication ...