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
2
votes
0answers
15 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
1answer
61 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 ...
4
votes
3answers
196 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
1answer
92 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 ...
4
votes
1answer
136 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
2answers
156 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 ...
4
votes
1answer
298 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 ...
0
votes
1answer
40 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 ...
0
votes
2answers
2k 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
0answers
46 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)?
0
votes
1answer
86 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 ...
2
votes
1answer
58 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 ...
7
votes
3answers
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
0answers
100 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 ...
2
votes
2answers
62 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
1answer
67 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
1answer
77 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 ...
1
vote
1answer
152 views

What PRNG function is this?

This is a 16-bit PRNG function, transcribed from assembly to C for easier reading: ...
9
votes
3answers
1k 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 ...
2
votes
1answer
1k 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
1answer
88 views

PETCs - How should one initialize PetscRandom?

The documentation of PETSc shows an example of usage: ...
0
votes
1answer
86 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
0answers
588 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
2answers
74 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]$, $...
3
votes
2answers
144 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 ...
6
votes
1answer
357 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 ...
1
vote
1answer
76 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. ...
6
votes
1answer
6k 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 ...
0
votes
1answer
33 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-...
1
vote
1answer
81 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+...
0
votes
2answers
61 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 ...
1
vote
1answer
77 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 ...
1
vote
1answer
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: ...
1
vote
3answers
171 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. ...
8
votes
1answer
454 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 ...
7
votes
1answer
95 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 ...
2
votes
1answer
125 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-...
5
votes
2answers
852 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 (...
4
votes
0answers
673 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 ...
3
votes
1answer
82 views

Randomly choose among N alternatives

I understand how to generate a random sequence of binary variables where 1 occurs with probability p and ...
8
votes
3answers
3k views

random number generation from cython

I want to make my python program fast by using cython, but my inner loop is still making slow python calls to the random number generator! Several years ago this same issue was raised by someone on ...
5
votes
1answer
116 views

How to assure that a number only contains a certain range of digits?

Say I would like to generate a pseudo-random number, which only contains the digits 1, 4, 7 (this is arbitrary). My first guess would be to create and array "147" and create random numbers in the ...
7
votes
3answers
786 views

How to handle large numbers of output data sets from a simulation/sensitivity analysis?

Somewhat related, but I think the question is distinct enough to justify a separate question. As a bit of background, I come from a observational/statistical Epidemiology background, working with ...
4
votes
3answers
501 views

Quality Measures for Various Pseudo-Random Number Generators

According to this paper, Ideally, a pseudorandom number generator would produce a stream of numbers that: are uniformly distributed, are uncorrelated, never repeats itself, ...
10
votes
1answer
790 views

How can I determine the initial values of pseudo-random number generator if the sequence is given?

Suppose I knew that a random number sequence was generated by a linear congruential generator. That is, $x_{n+1}=(aX_n+c) \bmod m$ If I am given the entire period (or at least a large contiguous ...
13
votes
1answer
12k views

How can I determine the period of my pseudo-random number generator?

Suppose I'm using a linear congruential pseudo-random number generator (PRNG). Given a seed $x_0$, the multiplying factor (a), the shift factor (c) and the modulus factor (m), how can I determine the ...
3
votes
1answer
66 views

Adding deliberate imperfection to RNG output - toolkits?

Are there any existing software toolkits, libraries, frameworks or whatever for studying the quality of pseudorandom number generators that allow one to add a known amount of imperfection - e.g ...
8
votes
4answers
2k views

How can I seed a parallel linear congruential pseudo-random number generator for maximal period?

Normally when I seed a sequential random number generator in C, I use the call srand(time(NULL)) then use rand() mod N ...
7
votes
2answers
6k views

Looking for C/C++ implementations of sampling from multinomial and Dirichlet distributions

I'm looking for C/C++ implementations of functions that return random variates multinomial and Dirichlet distributions. This is in the context of a calculation for posterior predictive p-values, part ...
19
votes
4answers
4k views

Is Fortuna or Mersenne Twister preferable as an algorithmic RNG?

A recent answer mentioned the use of Fortuna or Mersenne Twister Random Number Generators (RNGs) to seed a Monte Carlo simulation. I hadn't heard of Fortuna before so I looked it up - looks like it is ...