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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
59 views

Generating a random number with CDF $P(X \leq c) = 1-1/c$ in the interval $(1, + \infty)$. using uniform distribution

I have a uniform number generator in ($0, 1).$ I want to generate a random number with CDF $P(X \leq c) = 1-1/c$ in the interval $(1, + \infty)$. I know I should apply the inverse of my function to ...
AutisticRat's user avatar
2 votes
1 answer
219 views

Is there a law or theorem related to occurrence of an event with highest probability in a population with infinite size?

Assume, we have a key that appears in either of the three rooms randomly (red room, blue room, and green room). We have the following probability distribution: ...
Breeze's user avatar
  • 25
0 votes
1 answer
33 views

Random Walk and Moving Average for Stock Market Model

I model a stock price with a completely random walk: In each step I multiply the price with normal distributed random number with an mean of 1. Then I compute a signal, which is True if the moving ...
Ruediger Jungbeck's user avatar
0 votes
1 answer
42 views

Question about the inversion method for simulation of random variables [closed]

In the method called inversion we have : Let $U$ ~ unif(0,1) denote a uniform random variable on $(0,1)$. Then : $\mathbb{P}(F^{-1}(U))$ = $\mathbb{P}(U \leq F(x))=F(x)$ so $F^{-1}(U)$ has ...
John john's user avatar
  • 103
0 votes
0 answers
30 views

How does one sample from a gaussian distribution without a library? [duplicate]

I am looking to write a program that generates samples from a gaussian distribution with a certain mean and standard deviation. I am not allowed to use any library except a random number generator. Is ...
desert_ranger's user avatar
1 vote
1 answer
45 views

Bootstrapping CI around variance ratio from random regression model

I am interested in the ratio of random slope variance from a random slope and intercept model. I fit the model using lme4 as ...
stats-what's user avatar
1 vote
0 answers
22 views

Generate numbers between 0 and N in a random order guaranteeing uniqueness with efficient memory cost [closed]

I'm trying to think of a method i could use to generate the random numbers between 0 and N in a random order and with uniqueness that would use the smallest footprint of memory at the beginning and ...
eljiwo's user avatar
  • 111
21 votes
2 answers
4k views

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

Suppose I am generating random 4-digit numbers. Obviously there are 10,000 possible numbers, but the chances are I will get a duplicate long before I generate that many. Can anyone explain how I would ...
Avrohom Yisroel's user avatar
1 vote
1 answer
89 views

Sampling from Gaussian Process

I am learning the Gaussian process and feel confused about how three lines were generated in Fig 2.2(A) in the book "Gaussian Process For Machine Learning". As described by the author: "...
user3153824's user avatar
1 vote
1 answer
49 views

Drawing numbers using the CDF

Say I have a (generally high-dimensional) random variable $X$ with known, continuous CDF $F(X)$. Is there a good algorithm for drawing values of $X$ that doesn't require that I calculate the joint ...
Wilbur's user avatar
  • 211
2 votes
0 answers
26 views

Drawing random numbers with quadrature

In a comment on this question, the user 'probabilityislogic' says "No, not MCMC this thing! Quadrature this thing! only 2 parameters - quadrature is the "gold standard" for small ...
Wilbur's user avatar
  • 211
3 votes
0 answers
51 views

Generating uniformly distributed particles on a $n$-dimensional flat torus or periodic hypercube [closed]

I am trying to generate evenly distributed particles in an $n$-dimensional flat torus or a periodic hypercube. I am not sure if any of this approaches suffices. Can you suggest alternative methods for ...
Rober's user avatar
  • 31
12 votes
6 answers
2k views

How to generate from this distribution without inverse in R/Python?

I am working with a distribution with the following density: $$f(x) = - \frac{(\alpha+1)^2 x^\alpha \log(\beta x)}{1-(\alpha + 1)\log(\beta)}$$ and CDF $$\mathbb{P} (X \leq x) = \int_0^x - \frac{(\...
Lucas cantu's user avatar
2 votes
1 answer
82 views

Testing relationship between exponential and beta distributions using R

If X ~ Exp(3), Y ~ Exp(1) and h = X / (X + Y) then h ~ beta(1/3, 1) and E(h) = 1/4. But when I draw random deviates using the following R code, I find mean(h) ≈ 0.324 and the histogram doesn't ...
rob's user avatar
  • 21
2 votes
1 answer
37 views

Sampling from a distribution function $g_{x}$ that will follow $f_{x}$

I am using acceptance-rejection sampling to sample random variable $x$ according to distribution $f(x)$. The steps I followed are First generated uniformly distributed random variable $x$ from 0 to $...
Prab's user avatar
  • 21
4 votes
2 answers
214 views

How to generate a standard normal distributed time-series with a given ACF

I want to generate a standard normal distributed time-series. In addition the ACF of my timeseries should match a desired ACF. I have given lags 1 to 30 with the corresponding ACF-values. For further ...
Christian's user avatar
2 votes
0 answers
31 views

Relaxed magic-square generator distribution

This question is about a magic square generator, "relaxed" because it's only about one vector (row) in the square independent of all other rows; the individual elements are continuous and ...
Reinderien's user avatar
8 votes
2 answers
295 views

Generating uniformly distributed random solutions of a linear equation

Given $n+1$ variables $p_0, p_1, \ldots, p_n$ defined over $\mathbb{R}^{+}$ so that $\sum_{i=0}^np_i=1$, and given a real number $1<x<n$, I want to generate random solutions of the equation so ...
ABu's user avatar
  • 361
10 votes
7 answers
1k views

How to generate uniform distributed samples with given auto-correlation function

As I mentioned in the question title, I want to generate specific uniformly distributed samples. I need them to model a real world scenario. For my real data, I estimated a function, which ...
Christian's user avatar
0 votes
1 answer
37 views

Control Chart: Nelson alternating rule

The Nelson rules for control charts describe patterns, which are "special" and need our attention. One of these rules is the "alternation rule". According to Nelson it is "...
Semoi's user avatar
  • 701
5 votes
1 answer
347 views

random number generation of truncated multivariate normal distribution

I want to generate random numbers from truncated multivariate normal distribution specified as follows: $ \begin{bmatrix} Y \\ X \end{bmatrix} \sim N \begin{pmatrix} \begin{bmatrix} \mu_Y \\ \mu_X \...
user0131's user avatar
  • 345
6 votes
1 answer
161 views

Random number generator for non-central chi-squared with non-integer dimension

Does someone know of a random number generation algorithm for a non-central chi-squared distribution with a non-integer dimension? PS By algorithm, I am interested in the detailed procedure or ...
user378619's user avatar
0 votes
0 answers
68 views

Numerical Stability when Inverse CDF Sampling from Truncated Density

Let $f(x)$ be the pdf of a random variable that we want to truncate to the interval $[a,b]$ and then sample from it. Let $F(x)$ denote the corresponding cdf. We can use inverse cdf sampling and ...
yrx1702's user avatar
  • 681
1 vote
0 answers
32 views

Suppose $f: \mathbb{R}^n \to [0, 1]$ is known, how to sample $x \in \mathbb{R}^n$ such that $f(x)$ follows uniform distribution? [closed]

Suppose $f: \mathbb{R}^n \to \mathbb{R}$ is known, where evaluation and gradient computation is easy. How can I sample $x \in \mathbb{R}^n$ such that $f_x \in \mathbb{R}$ follows uniform distribution? ...
orematasaburo's user avatar
0 votes
0 answers
63 views

How many toss a coin attempts required so the noise is always less than 1%?

I don't know what is it in statistic term, but I will say it the noise. Noise is defined as absolute difference between real percentage result after experiment and ideal probability. The question is ...
Muhammad Ikhwan Perwira's user avatar
2 votes
1 answer
120 views

Generate two random correlation matrices which share equal correlations

My setting is, I want to simulate a data set in two conditions, e.g. control and disease. I want them to share mostly the same correlations except some should be different to simulate a "signal&...
Sinraw's user avatar
  • 21
1 vote
1 answer
94 views

Generating random variables from a mixture of Normal distributions and Exponential distribution using composition method

How can I sample from a mixture distribution in particular a mixture of Normal distributions and Exponential distribution in R using composition method? For instance if I want to sample from: $0.3\...
Tegig's user avatar
  • 39
1 vote
1 answer
102 views

Perfect sampling and inverse transform sampling

Firstly, looking at the discussion https://math.stackexchange.com/questions/241315/three-ideas-of-perfect-sampling, the term "perfect sampling" does not seem adequate, since there are ...
Ludwig's user avatar
  • 63
1 vote
1 answer
18 views

How can I find the k-th smallest element of my list of random numbers? [closed]

I have generated exponential random numbers using x <- rexp(1000,1) with set.seed(1). I can look at them using ...
racine_carree's user avatar
7 votes
2 answers
320 views

Element-wise comparisons of sorted subsets of random numbers yield nonrandom results

Say we have a random number generator. It generates 2000 numbers that we put in two arrays, 1000 numbers each. Like this (here shorter arrays used to illustrate the point): [4, 20, 5, 6] [7, 21, 3, 3] ...
user2669285's user avatar
12 votes
1 answer
637 views

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 ...
ColorStatistics's user avatar
2 votes
1 answer
208 views

Pseudo-dice probability distribution

Given the following data, is there an algorithmic way to generate a probability distribution? Data: min, max, and average results of "die". Known Trend: results will always be weighted ...
Learn34's user avatar
  • 21
3 votes
2 answers
85 views

Random sampling from a super level set

I have a random sampler from a region $X$. Suppose, I have a function $f: X \to \mathbb{R}$, where I can explicitly evaluate $f(x)$ and also obtain the gradient $\frac{\partial f}{\partial x}$ easily (...
orematasaburo's user avatar
8 votes
1 answer
168 views

Generating random variable which has a power distribution of Box and Tiao (1962)

Box and Tiao (Biometrika 1962) use a distribution whose density has the following form: $$f(x; \mu, \sigma, \alpha) = \omega \exp\left\{ -\frac{1}{2} \Big\vert\frac{x-\mu}{\sigma}\Big\vert^{\frac{2}{(...
user67724's user avatar
  • 313
10 votes
2 answers
597 views

Why doesn't R use Inverse Transform Sampling to sample from the Exponential Distribution?

I was reading this question about the algorithm that R uses to sample from the Exponential($\lambda$) distribution. It looks like R uses the Ahrens-Dieter algorithm to sample from the exponential ...
ColorStatistics's user avatar
1 vote
1 answer
64 views

Using KDE to approximate a Price vs Quantity curve

I am trying to approximate Price-vs-Quantity (P-Q) curve of a dynamic product (think Hotels, Airlines etc). As you can imagine, if you take a hotel property, the price of rooms (assuming the same room ...
sharathnatraj's user avatar
2 votes
0 answers
56 views

How to simulate artifical data for multinomial regression? [duplicate]

I want to use some predictors (for example, $x_1$ and $x_2$ below) to simulate the multinomial outcome (for example, with 3 levels). Below are the codes I found in another question regarding ...
spencer886's user avatar
4 votes
2 answers
227 views

Creating a random sparse precision matrix?

In my current project, I want to create a random sparse precision matrix $\boldsymbol{P}=\boldsymbol{\Sigma}^{-1}$ (the inverse of a covariance matrix $\boldsymbol{\Sigma}$). My current procedure ...
J.Galt's user avatar
  • 545
1 vote
1 answer
52 views

how to sample two random variables from different distributions and requiring one is always larger than the other

I know one way is to sample A and B independently and then reject the samples where A<B. But I wonder if there is an easier method?
Nicolas Fabre's user avatar
3 votes
1 answer
117 views

Draw random numbers from finite mixture model

Setup Let X follow a fininte mixture model with density \begin{equation} f=\lambda f_1+(1-\lambda) f_2 \end{equation} Where $f_1$ and $f_2$ are both log-normal densities with parameters $(\mu_1, \...
FicusBenji's user avatar
1 vote
0 answers
194 views

Why is it difficult to sample from a multivariate distribution? [closed]

The Monte Carlo Markov Chain method requires sampling from a multivariate distribution. This is because the Markov Chain process requires dependent draws. See 1:55 at https://www.youtube.com/watch?v=...
Snoopy's user avatar
  • 513
0 votes
0 answers
49 views

Sphere Point Picking

As explained here, sphere point picking can be performed using the easy formula $x$ = $\sqrt{1-v^2}\cos\theta$ $y$ = $\sqrt{1-v^2}\sin\theta$ $z$ = $ v$ where $\theta\in [0, 2\pi]$ and $v \in [-1,1]...
user2966501's user avatar
0 votes
1 answer
48 views

Generating sample data from a specified model

I am reading a book on longitudinal correlated data analysis available in https://www.taylorfrancis.com/books/mono/10.1201/9781420035285/generalized-estimating-equations-james-hardin-joseph-hilbe In ...
Daniel's user avatar
  • 123
0 votes
0 answers
35 views

How much randomness is required for Gibbs sampling?

I am attempting to parallelize a program that executes hundreds of calls to Mallet's getSampledDistribution method, which is essentially an execution of Gibbs sampling over a topic distribution which ...
Fledgling Pidgeon's user avatar
1 vote
2 answers
580 views

Python/numpy - conditional sampling of variables, distribution of subsequent value is based on result of previous value

I am trying to generate a random sample of multiple variables which are loosely related to each other. Meaning that "allowed" values of some variables depend on the value which is set for ...
Maksim Khaitovich's user avatar
7 votes
2 answers
571 views

How can I generate random observations from a concrete copula?

Let us assume that we have two continuous random variables $X$, $Y$, with known distributions (not necessarily normal), connected/related via a concrete copula. What is a procedure to generate random ...
Vicent's user avatar
  • 769
0 votes
0 answers
191 views

Generating multivariate random variable with normal and exponential marginals

I have a collection of data points of the form $[U, V, X, Y]$, where $U$ ~ $N(\mu_1, \sigma_1)$; $V$ ~ $N(\mu_2, \sigma_2)$; $X$ ~ $exp(\lambda_1)$; and $Y$ ~ $exp(\lambda_2)$, and I am looking to ...
Pistol Pete's user avatar
0 votes
0 answers
109 views

Correlation matrix from pairwise correlations with specified structure

I need to simulate multivariate normal samples with a pre-specified correlation structure. The structure is such that the bigger the (GPS) distance between two points, the smaller the correlation (...
Skumin's user avatar
  • 204
0 votes
0 answers
92 views

How to weight probabilites of getting sampled depending on the frequency of occurrence?

Unfortunately I'm struggling to describe my problem mathematically. I have 2000 strings, many of which are repeated. Now I want to write a 'random' sampling algorithm that produces 100 samples out of ...
Zderfo's user avatar
  • 1
1 vote
2 answers
131 views

Variance of the sum of multiple random number generators

Let's assume I have "n" random number generators, each one has a different variance value, but has the same mean value, zero. If I generate "n" random numbers with these generators,...
Faruk UNAL's user avatar

1
2 3 4 5
16