Questions tagged [random-number-generation]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
33 views

Algorithm for Probabilities in a "Random" Integers Runs test

Suppose you have a set of N random integers. ( aka bytes 0..255 ) You then consider each subsequent neighbor as "ascending" or "descending", counting the number of consecutive ...
David GSM's user avatar
0 votes
1 answer
46 views

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

This question arises from my attempt to mix two different RNGs. I'd like to mix them choosing the best of the two according to the operations I need to carry out to achieve better performance. I'm ...
Tortar's user avatar
  • 111
0 votes
0 answers
56 views

generating multivariate Gaussian samples with constraints

Using GRFs, one generates samples $x \sim N(m,K)$ with arbitrary mean $m$ and covariance matrix $K$ using a scalar Gaussian generator as $x = m + Lu$, where $L$ is a lower triangular matrix, such that ...
computational_scientist's user avatar
0 votes
1 answer
56 views

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

I am currently dealing with exponential decay (of muons). The PDF is the following: https://wikimedia.org/api/rest_v1/media/math/render/svg/fdacadb747bac9932ffd02ee35cf3cbd0bc0b4c8 And I am told that ...
d-d's user avatar
  • 1
1 vote
0 answers
86 views

approximate Poisson disk / blue noise sampling

Poisson disk or blue noise sampling consists of finding a random, maximal set of points $\{x_i\}$ in a domain $\Omega$ such that $\|x_i - x_j\| \ge r$ for some fixed radius $r$ and for all $i$, $j$. ...
Daniel Shapero's user avatar
0 votes
0 answers
104 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 ...
user196574's user avatar
0 votes
1 answer
163 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 ...
Roshan Shrestha's user avatar
2 votes
0 answers
93 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 ...
Lorents's user avatar
  • 131
-1 votes
1 answer
84 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 ...
Chris 's user avatar
  • 101
1 vote
1 answer
44 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 ...
Mars's user avatar
  • 121
0 votes
0 answers
127 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 ...
Akshat Mehrotra's user avatar
0 votes
0 answers
95 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 ...
Pruthvi Mehta's user avatar
2 votes
0 answers
183 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 ...
Clej's user avatar
  • 153
-1 votes
1 answer
45 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(...
Pruthvi Mehta's user avatar
2 votes
0 answers
54 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 ...
Userhanu's user avatar
  • 151
1 vote
1 answer
67 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 ...
user30385's user avatar
6 votes
3 answers
1k 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/...
physkets's user avatar
1 vote
1 answer
179 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 ...
Pourya Vakilipourtakalou's user avatar
4 votes
1 answer
224 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 ...
Stefano Campanella's user avatar
1 vote
2 answers
172 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 ...
user62783's user avatar
4 votes
1 answer
671 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 ...
user62783's user avatar
0 votes
1 answer
57 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 ...
Victor Buendía's user avatar
0 votes
2 answers
5k 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 ...
juhist's user avatar
  • 151
1 vote
0 answers
75 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)?
Alessandra Porporato's user avatar
0 votes
1 answer
101 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 ...
Ayush Agrawal's user avatar
2 votes
1 answer
73 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 ...
CRG's user avatar
  • 347
7 votes
3 answers
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 ...
Thomas Arildsen's user avatar
1 vote
0 answers
153 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 ...
myseun's user avatar
  • 53
2 votes
2 answers
94 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 ...
sh1's user avatar
  • 141
1 vote
1 answer
101 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 ...
bernie's user avatar
  • 165
1 vote
1 answer
84 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 ...
velut luna's user avatar
2 votes
1 answer
186 views

What PRNG function is this?

This is a 16-bit PRNG function, transcribed from assembly to C for easier reading: ...
Andrew Cheong's user avatar
10 votes
3 answers
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 ...
Jonas Greitemann's user avatar
2 votes
1 answer
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 ...
Pandya's user avatar
  • 121
1 vote
1 answer
106 views

PETCs - How should one initialize PetscRandom?

The documentation of PETSc shows an example of usage: ...
guhur's user avatar
  • 133
0 votes
1 answer
143 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: ...
guhur's user avatar
  • 133
1 vote
0 answers
928 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 ...
Joseph's user avatar
  • 131
1 vote
2 answers
100 views

Maintain Uniform Distribution across Subranges

Note: this is a continuation of Generate Random Number outside Bounds. I have a function (thanks to the previous question) with the following prototype which returns an integer in the range $[0,b]$, $...
user19087's user avatar
  • 143
3 votes
2 answers
268 views

Generate Random Number outside Bounds:

Say I have a random number generator that generates a number within [0, RAND_MAX], and RAND_MAX < UINT_MAX. How do I ...
user19087's user avatar
  • 143
6 votes
1 answer
486 views

Generating random numbers for long molecular dynamics simulations

I've written a basic 2D Langevin dynamics simulator in C++, for a particle in a potential, solving the equation: $$M\ddot{X} = - \nabla U(X) - \gamma M \dot{X} + \sqrt{2 \gamma k_B T M} R(t)$$ This ...
dr.blochwave's user avatar
1 vote
1 answer
86 views

Shifting points in fortran

Hello I am trying to shift points which have been previously generated in the square area. I am having a trouble with some additional conditions how they should have been shifted. ...
Beginner in fort's user avatar
6 votes
1 answer
11k views

How do I generate Maxwell-Boltzmann variates using a uniform distribution random number generator?

I am doing a molecular dynamics simulation. I need to assign initial velocities to the atoms. I want to assign the initial velocities which follow the Maxwell-Boltzmann distribution. How do I ...
Yogesh Yadav's user avatar
0 votes
1 answer
37 views

Generating pseudorandom sequences based on measured sequences

I'm looking for an algorithm to generate discrete-time pseudorandom sequences based on other sequences I already have that would be used to train the algorithm. More specifically, I have some time-...
siritinga's user avatar
  • 203
1 vote
1 answer
95 views

Sampling from the Generalized Beta of the Second Kind in Fortran

I need to sample from the generalized beta of the second kind (GB2) distribution (McDonald, 1984, Econometrica). Its PDF has the form $$ f_{a,b,p,q}(x) = \frac{|a|x^{ap-1}}{b^{ap}B(p,q)(1+(x/b)^a)^{p+...
uncecon's user avatar
  • 11
0 votes
2 answers
65 views

Maths calculations for randomly generated numbers don't match computed averages

Ok, It was hard to explain my problem in the title. I hope it made enough sense to peak the curiosity of some of you. What I've been trying to do is find the relationship between the amount of random ...
Dennis Callanan's user avatar
1 vote
1 answer
84 views

optimising changing the range of integers from random number generation

I'm looking to find the most efficient way to change integers from a random number generator to a different inclusive number range. I know of 2 ways so far: Change the number into a decimal in the ...
Dylan Sawchuk's user avatar
1 vote
1 answer
2k views

Calculating periodicity of a pseudo random number generator (Middle-square method) [closed]

Below is a Python code that calculates the periodicity of the middle-square method for a given 4 digit-numbers: ...
Remi.b's user avatar
  • 113
1 vote
3 answers
247 views

Quality of randomness in generated random number

I have generated a list of 3 random number where each summed to 1. I would like to assess the quality of randomness. What is the best mechanism to assess this randomness? E.g my random numbers are. ...
biz14's user avatar
  • 133
8 votes
1 answer
502 views

WELL pseudo-random number generations

I've used MT19937 in a test harness to generate uniformly (unsigned) 32-bit [0, $2^{32}$- 1] values, based on the original Authors' mt19937.c implementation, to ...
Brett Hale's user avatar
7 votes
1 answer
108 views

Shall I derandomize a randomized algorithm in real application?

In general (and in real application), suppose I am using a randomized algorithm (e.g. Use MCMC to sample from a distribution and then compute $E(f(x))$ for some function $f$) Assume my algorithm will ...
wh0's user avatar
  • 183