Questions tagged [random-generation]

The act of generating a sequence of numbers or symbols randomly, or (almost always) pseudo-randomly; i.e., with lack of any predictability or pattern.

Random generation, or random number generation is the use of mechanical or electronic devices or more usually algorithms to produce a sequence of numbers which lack any predictability or regularities, generally according to some particular probability distribution over the numbers or symbols, often equiprobably (when this makes sense). These values are used to approximate expectations, validate models, or to reproduce random experiments. Most random generators are pseudo-random in that they produce a deterministic sequence that can be repeated by using the "seed" the generators are initialised with.

Reference: http://en.wikipedia.org/wiki/Random_number_generation

780 questions
94
votes
7 answers

How to generate uniformly distributed points on the surface of the 3-d unit sphere?

I am wondering how to generate uniformly distributed points on the surface of the 3-d unit sphere? Also after generating those points, what is the best way to visualize and check whether they are truly uniform on the surface $x^2+y^2+z^2=1$?
Qiang Li
  • 1,295
41
votes
2 answers

Am I creating bias by using the same random seed over and over?

In almost all of the analysis work that I've ever done I use: set.seed(42) It's an homage to Hitchhiker's Guide to the Galaxy. But I'm wondering if I'm creating bias by using the same seed over and over.
Brandon Bertelsen
  • 7,232
  • 9
  • 41
  • 48
41
votes
3 answers

What exactly is a seed in a random number generator?

I tried some usual google search etc. but most of the answers I find are either somewhat ambiguous or language/library specific such as Python or C++ stdlib.h etc. I am looking for a language agnostic, mathematical answer, not the specifics of a…
Della
  • 533
19
votes
1 answer

Set seed before each code block or once per project?

It is standard advice to set a random seed so that results can be reproduced. However, since the seed is advanced as pseudo-random numbers are drawn, the results could change if any piece of code draws an additional number. At first glance, version…
19
votes
3 answers

Generate uniformly distributed weights that sum to unity?

It is common to use weights in applications like mixture modeling and to linearly combine basis functions. Weights $w_i$ must often obey $w_i ≥$ 0 and $\sum_{i} w_i=1$. I'd like to randomly choose a weight vector $\mathbf{w} = (w_1, w_2, …)$ from a…
Chris
  • 581
  • 1
  • 5
  • 10
16
votes
1 answer

If so many people use set.seed(123) doesn't that affect randomness of world's reporting?

It seems like everyone just uses set.seed(123) or set.seed(1234) when they are doing random sampling. If so many people use just a select few integers for set.seed(), doesn't that mean that everyone is drawing from the same state of the random…
conv3d
  • 636
14
votes
3 answers

How to generate uniformly distributed points in the 3-d unit ball?

I have posted a previous question, this is related but I think it is better to start another thread. This time, I am wondering how to generate uniformly distributed points inside the 3-d unit sphere and how to check the distribution visually and…
Qiang Li
  • 1,295
13
votes
2 answers

How do I sample from a discrete (categorical) distribution in log space?

Suppose I have a discrete distribution defined by the vector $\theta_0, \theta_1, ..., \theta_N$ such that category $0$ will be drawn with probability $\theta_0$ and so on. I then discover that some of the values in distribution are so small that…
12
votes
1 answer

Generating random vectors with constraints

I need to create random vectors of real numbers a_i satisfying the following constraints: abs(a_i) < c_i; sum(a_i)< A; # sum of elements smaller than A sum(b_i * a_i) < B; # weighted sum is smaller than B aT*A*a < D #…
12
votes
1 answer

What is B. D. Ripley's method of seeding the Mersenne-Twister RNG?

R's documentation behind ?runif states that the default RNG is "Mersenne-Twister": From Matsumoto and Nishimura (1998); code updated in 2002. A twisted GFSR with period 2^19937 - 1 and equidistribution in 623 consecutive dimensions (over the whole…
12
votes
4 answers

Which numbers are least likely to be selected by people in a lottery?

The Mega Millions is over $500 million today. I remember reading a JSTOR paper about some numbers that are most unlikely to be chosen. For example lots of people choose 7 because it's their lucky number, and I want the opposite of that. However my…
12
votes
3 answers

How to generate sorted uniformly distributed values in an interval efficiently?

Let's say I want to generate a set of random numbers from the interval (a, b). The generated sequence should also have the property that it is sorted. I can think of two ways to achieve this. Let n be the length of the sequence to be generated. 1st…
ultrajohn
  • 231
  • 2
  • 5
11
votes
1 answer

References and Best practices for setting seeds in pseudo-Random Number Generation

In this document, that concerns the "set seed" command, Stata people discuss issues related to the setting of seeds when generating pseudo-random numbers. A notable "don't" is "don't use serially the sequence of natural numbers as seeds, because…
10
votes
3 answers

Given a coin with unknown bias, generate variates from a fair coin efficiently

Given a coin with unknown bias $p$, how can I generate variates — as efficiently as possible — that are Bernoulli-distributed with probability 0.5? That is, using the minimum number of flips per generated variate.
Neil G
  • 15,219
9
votes
1 answer

Is there such a thing as a "good/bad" seed in pseudo-random number generation?

Well, I don't really have much to add to the title. I tend not to use seeds in preudo-random number generation, but they are handy when an initial research project that includes simulations expands to include more aspects of the same simulation…
1
2 3 4