Tag Info

Accepted

Why is generating 8 random bits uniform on (0, 255)?

TL;DR: The sharp contrast between the bits and coins is that in the case of the coins, you're ignoring the order of the outcomes. HHHHTTTT is treated as the same as TTTTHHHH (both have 4 heads and 4 ...
• 92.6k

Brain teaser: How to generate 7 integers with equal probability using a biased coin that has a pr(head) = p?

Flip the coin twice. If it lands HH or TT, ignore it and flip it twice again. Now, the coin has equal probability of coming up ...
• 661

Generate a random variable with a defined correlation to an existing variable(s)

I will describe the most general possible solution. Solving the problem in this generality allows us to achieve a remarkably compact software implementation: just two short lines of ...
• 330k
Accepted

Generating random numbers manually

If "manually" includes "mechanical" then you have many options available to you. To simulate a Bernoulli variable with probability half, we can toss a coin: $0$ for tails, $1$ for ...
• 23.8k
Accepted

Generating correlated binomial random variables

Binomial variables are usually created by summing independent Bernoulli variables. Let's see whether we can start with a pair of correlated Bernoulli variables $(X,Y)$ and do the same thing. Suppose ...
• 330k
Accepted

Finding a way to simulate random numbers for this distribution

There is a straightforward (and if I may add, elegant) solution to this exercise: since $1-F(x)$ appears like a product of two survival distributions: (1-F(x))=\exp\left\{-ax-\frac{b}{p+1}x^{p+1}\...
• 107k

Brain teaser: How to generate 7 integers with equal probability using a biased coin that has a pr(head) = p?

Assume that $p \in (0,1)$. Step 1:. Toss the coin 5 times. If the outcome is $(H, H, H, T, T)$, return $1$ and stop. $(H, H, T, T, H)$, return $2$ and stop. $(H, T, T, H, H)$, return $3$ and ...
• 47.3k

Generating random numbers manually

If you can get access to a very precise clock, you can extract the decimal part of the current time and turn it into a uniform, from which you can derive a normal simulation by the Box-Müller ...
• 107k
Accepted

Who is Gail Gasram?

It looks like "Gail Gasram" is "Marsaglia G" (George Marsaglia's surname and first initial) spelled backwards.
• 516
Accepted

What exactly is a seed in a random number generator?

Most pseudo-random number generators (PRNGs) are build on algorithms involving some kind of recursive method starting from a base value that is determined by an input called the "seed". The default ...
• 130k
Accepted

If I generate a random symmetric matrix, what's the chance it is positive definite?

If your matrices are drawn from standard-normal iid entries, the probability of being positive-definite is approximately $p_N\approx 3^{-N^2/4}$, so for example if $N=5$, the chance is 1/1000, and ...
• 14k
Accepted

How to generate random integers between 1 and 4 that have a specific mean?

I agree with X'ian that the problem is under-specified. However, there is an elegant, scalable, efficient, effective, and versatile solution worth considering. Because the product of the sample mean ...
• 330k

Why is the term "Monte Carlo simulation" used instead of "Random simulation"?

Nicholas Metropolis claimed in 1987 that It was at that time that I suggested an obvious name for the statistical method - a suggestion not unrelated to the fact that Stan[islaw ...
• 129k
Accepted

How many numbers can I generate and be 90% sure that there are no duplicates?

The approximation given in the Wikipedia article (also mentioned in the paper by Diaconis & Mosteller (1989)) works well here. Suppose $N$ 4-digit numbers are drawn with replacement from a pool of ...
• 31k
Accepted

R: Problem with runif: generated number repeats (more often than expected) after less than 100 000 steps

The documentation of R on random number generation has a few sentences at its end, that confirm your expectation of 32-bit integers being used and might explain what you are observing: Do not rely ...
• 451

Would it be possible to generate data from real data in medical research?

No, this is not good practice. "Oversampling" the data you have makes your model believe it has more real data than it actually has, and makes it underestimate the probability of actual data ...
• 129k
Accepted

How to sample from Cantor distribution?

Easy: sample from a Uniform$(0,1)$ distribution and recode from binary to ternary, interpreting each "1" as a "2". (This is the inverse probability transform approach: it does indeed invert the CDF!) ...
• 330k
Accepted

Algorithm for sampling fixed number of samples from a finite population

Yes. Collect the first $k$ items encountered into the cache. At steps $j=k+1, \ldots, n,$ place item $j$ in the cache with probability $k/j,$ in which case you will remove one of the existing items ...
• 330k
Accepted

• 330k

What exactly is a seed in a random number generator?

First, there is no true randomness in today's computer-generated "random numbers." All pseudorandom generators use deterministic methods. (Possibly, quantum computers will change that.) The ...
• 57.1k

Brain teaser: How to generate 7 integers with equal probability using a biased coin that has a pr(head) = p?

Divide a box into seven equal-area regions, each labeled with an integer. Throw the coin into the box in such a way that it has equal probability of landing in each region. This is only half in jest -...
• 92.6k

Generating Multivariate Uniform Distribution in R

It depends a little bit on the terminology, but usually multivariate uniform refers to a distribution where every point in $[a,b]^d$ is equally likely. Hence, the dimensions are independent, and you ...
• 838

Who is Gail Gasram?

Diehard Code After some extensive digging, it appears that Gail Gasram participated in developing Diehard code, which represented a suite of programs for testing random number generators. Furthermore,...
• 2,280

Will this introduce bias into what should be random numbers?

Let's count and see. By construction of the file, all 4-bit strings are equally likely. There are 16 such strings. Here they are: ...
• 20.4k
Accepted

What is meant by "Laplace noise"?

You are correct, adding Laplace noise means that to your variable $X$ you add variable $Y$ that follows Laplace distribution. There are multiple reasons why it is called noise. First, think of signal ...
• 140k
Accepted

How to generate a $\pm 1$ sequence with mean $0.05$?

Your desired mean is given by equation: $\frac{N\cdot p - N \cdot (1-p)}{N} = .05$ from which follows that the probability of the 1s should be ...
• 1,196
Accepted

Sampling from $x^2\phi(x)$?

Some guesswork suggest that $X$ perhaps can be simulated by a suitable power-transformation of a Gamma random variable $Y$ multiplied by a random sign to make the resulting density symmetric about ...
• 11.5k