Randomness is a way to mathematically model uncertainty. We often assume to have access to some well-defined source of random numbers, or that input values or events follow some probability distribution.
Questions tagged [randomness]
259 questions
58
votes
5 answers
Why is the Mersenne Twister regarded as good?
The Mersenne Twister is widely regarded as good. Heck, the CPython source says that it "is one of the most extensively tested generators in existence." But what does this mean? When asked to list properties of this generator, most of what I can…
Veedrac
- 992
- 1
- 7
- 16
39
votes
7 answers
Can PRNGs be used to magically compress stuff?
This idea occurred to me as a kid learning to program and
on first encountering PRNG's. I still don't know how realistic
it is, but now there's stack exchange.
Here's a 14 year-old's scheme for an amazing compression algorithm:
Take a PRNG and seed…
user15782
36
votes
6 answers
Differences and relationships between randomized and nondeterministic algorithms?
What differences and relationships are between randomized algorithms and nondeterministic algorithms?
From Wikipedia
A randomized algorithm is an algorithm which employs a degree of
randomness as part of its logic. The algorithm typically uses
…
Tim
- 5,035
- 5
- 37
- 71
36
votes
6 answers
Uniform sampling from a simplex
I am looking for an algorithm to generate an array of N random numbers, such that the sum of the N numbers is 1, and all numbers lie within 0 and 1. For example, N=3, the random point (x, y, z) should lie within the triangle:
x + y + z = 1
0 < x <…
Ruofeng
- 463
- 1
- 4
- 4
33
votes
2 answers
How asymptotically bad is naive shuffling?
It's well-known that this 'naive' algorithm for shuffling an array by swapping each item with another randomly-chosen one doesn't work correctly:
for (i=0..n-1)
swap(A[i], A[random(n)]);
Specifically, since at each of $n$ iterations, one of $n$…
Steven Stadnicki
- 2,539
- 15
- 25
31
votes
2 answers
Simulating a probability of 1 of 2^N with less than N random bits
Say I need to simulate the following discrete distribution:
$$
P(X = k) =
\begin{cases}
\frac{1}{2^N}, & \text{if $k = 1$} \\
1 - \frac{1}{2^N}, & \text{if $k = 0$}
\end{cases}
$$
The most obvious way is to draw $N$ random bits and check if all of…
nalzok
- 1,111
- 11
- 21
30
votes
10 answers
Generating uniformly distributed random numbers using a coin
You have one coin. You may flip it as many times as you want.
You want to generate a random number $r$ such that $a \leq r < b$ where $r,a,b\in \mathbb{Z}^+$.
Distribution of the numbers should be uniform.
It is easy if $b -a = 2^n$:
r = a +…
Pratik Deoghare
- 1,751
- 2
- 14
- 22
26
votes
12 answers
Is von Neumann's randomness in sin quote no longer applicable?
Some chap said the following:
Anyone who attempts to generate random numbers by deterministic means is, of course, living in a state of sin.
That's always taken to mean that you can't generate true random numbers with just a computer. And he said…
Paul Uszak
- 1,602
- 1
- 13
- 21
25
votes
1 answer
How to prove correctness of a shuffle algorithm?
I have two ways of producing a list of items in a random order and would like to determine if they are equally fair (unbiased).
The first method I use is to construct the entire list of elements and then do a shuffle on it (say a Fisher-Yates…
edA-qa mort-ora-y
- 1,538
- 12
- 15
25
votes
7 answers
Can we generate random numbers using irrational numbers like π and e?
Irrational numbers like $\pi$, $e$ and $\sqrt{2}$ have a unique and non-repeating sequence after the decimal point. If we extract the $n$-th digit from such numbers (where $n$ is the number of times the method is called) and make a number with the…
Abhradeep Sarkar
- 377
- 1
- 3
- 6
24
votes
3 answers
Is rejection sampling the only way to get a truly uniform distribution of random numbers?
Suppose that we have a random generator that outputs
numbers in the range $[0..R-1]$ with uniform distribution and we
need to generate random numbers in the range $[0..N-1]$
with uniform distribution.
Suppose that $N < R$ and $N$ does not evenly…
Vor
- 12,743
- 1
- 31
- 62
24
votes
3 answers
Are all pseudo-random number generators ultimately periodic?
Are all pseudo-random number generators ultimately periodic? Or are they periodic at all in the end?
By periodic I mean that, like rational numbers, they in the end generate a periodic subsequence...
And pseudo-random means algorithmic/mathematical…
user13675
- 1,684
- 12
- 19
24
votes
8 answers
What randomness really is
I'm a Computer Science student and am currently enrolled in System Simulation & Modelling course. It involves dealing with everyday systems around us and simulating them in different scenarios by generating random numbers in different distributional…
MAK7
- 343
- 1
- 7
22
votes
2 answers
How does an operating system create entropy for random seeds?
On Linux, the files /dev/random and /dev/urandom files are the blocking and non-blocking (respectively) sources of pseudo-random bytes.
They can be read as normal files:
$ hexdump /dev/random
0000000 28eb d9e7 44bb 1ac9 d06f b943 f904 8ffa
0000010…
Adam Matan
- 427
- 4
- 7
22
votes
11 answers
How to simulate a die given a fair coin
Suppose that you're given a fair coin and you would like to simulate the probability distribution of repeatedly flipping a fair (six-sided) die. My initial idea is that we need to choose appropriate integers $k,m$, such that $2^k = 6m$. So after…
probability_guy
- 223
- 1
- 2
- 4