Questions tagged [random]

Questions about random number generation and the properties of numbers so generated.

Filter by
Sorted by
Tagged with
0 votes
0 answers
68 views

Sum of elements products equals to zero

I need to evaluate $\sum_i a_i b_i=0$, subject to the constraint $\sum_i a_i=1$. For the "a" summation being equal to 1, I generated a random list of 10 elements using ...
user avatar
  • 13
1 vote
1 answer
89 views

While inside a function body does not work as expected [closed]

I'm trying to write a function that return a randomly created rational polynomial function that has a discontinuities points. I already have a function that generates random rational polynomial (...
user avatar
  • 69
5 votes
2 answers
458 views

How do you generate a random number with a pre-specified probability distribution?

I want to generate a random real number between 0 and 1 but not distributed uniformly but with a probability distribution say, 2 Sin[ pi x ]^2 which integrates to 1 ...
user avatar
6 votes
3 answers
329 views

I want to count number of points inside the given shape

...
user avatar
0 votes
2 answers
115 views

How to generate random dots with given distances?

I am interested in the following problem, and am curious if Mathematica could be used to solve it. I start with a radius function $\rho:D\to \mathbf{R}_{\ge 0}$ on a region $D\subseteq \mathbf{R}^n$. ...
user avatar
1 vote
1 answer
72 views

How to run multiple random process and plot its average for a non-autonomous logistic model?

This problem is a continuation of the discussion from here, with random impulse function as discussed in here to formed the following: ...
user avatar
  • 173
0 votes
0 answers
38 views

Spanning Subgraphs of random sizes with probabilities on edges

I need a way of taking some graph G and obtaining a spanning subset of G where each edge $e_i$ has some probability $P_i$ of being in the subgraph. So the size of the edge sets of each random subgraph ...
user avatar
0 votes
2 answers
58 views

Random Variate inside a function causing the function to behave unexpectedly

I define a Random Variable drawn from a custom probability density. ...
user avatar
3 votes
3 answers
256 views

How can I rotate a cube uniformly?

Background Alice, Bob, and the average shadow of a cube I use the following code to simulate this experiment, ...
user avatar
  • 6,510
3 votes
3 answers
139 views

How to shuffle just one column of table/list?

I have a list in form {{X1,Y1,type},....{Xn,Yn,type}}. X and Y are coordinates and type is a number between 1 to 15, the length of the list is 12000, so I can not upload the data here. I need to keep (...
user avatar
  • 383
4 votes
2 answers
146 views

RandomReal vs Random[Real

Let's say I need random numbers with increasing precision to simulate a particular function, so I try: ...
user avatar
  • 14.8k
12 votes
3 answers
446 views

Generating a matrix with specific number of 1's in every row and column

I would like to have a function f(n,k) that generates a random nxn matrix with k elements equal to 1 in each row and column and has an all-zero diagonal, with all other elements equal to 0. In other ...
user avatar
  • 123
2 votes
2 answers
93 views

Verifying probabilities equality by imposing conditions

I'd like to verify the following equality in Mathematica: $$ P(Z_1+Z_2=2,Z_1=1,Z_2=1)=P(Z_1=1,Z_2=1) $$ by knowing that $Z_1,Z_2 \in \lbrace 1,2,3,4 \rbrace$ are two independent and uniform random ...
user avatar
0 votes
1 answer
50 views

How to create a real number generator whose value is persistent between kernel restarts?

Suppose I have a function f[x_] := RandomReal[] If I set x_=2 and f[2]=.2134.., I want <...
user avatar
  • 199
5 votes
2 answers
257 views

Optimizing sequential computation

The following question came up in reading group discussion of paper -- imagine taking two vectors, multiplying each by a random matrix, then taking tanh pointwise. If you repeat this process forever, ...
user avatar
0 votes
1 answer
71 views

Is there a difference between generating and loading data?

EDIT-1 This is a minimal example where an error occurs after 44538 samples generated in d1 upon importing as d2. Note that if <...
user avatar
1 vote
0 answers
40 views

How to generate a Gaussian random velocity field

Let us assume we have a 2-dimensional velocity field $\textbf{u}=(u_x,u_y)$ defined via its stream function $\psi(\textbf{x})$ as \begin{cases} u_x=\partial_y\psi(\textbf{x}) \\ u_y=-\partial_x\psi(\...
user avatar
1 vote
0 answers
37 views

Help request understanding the use of SeedRandom [closed]

I want to use SeedRandom inside of a code in which I use SmoothKernelDistribution to obtain the pdf of a stochastic process at a determined time as ...
user avatar
4 votes
2 answers
78 views

random choice of multiple lists but delete element chosen

I want to make a function which takes lists as an input and outputs one element out of one of the list with uniform probability (if for example we have 2 lists, one with 7 and one with 3 elements, ...
user avatar
8 votes
1 answer
270 views

How to compute RandomReal faster?

I have variables $E_{1},E_{3}$ that are bounded in the following way: $$ \tag 1 E_{1}>m_{1}, \quad E_{3}>m_{3}, E_{2}\equiv m-E_{1}-E_{3}>m_{2}, \\ -1 < \frac{E_{2}^{2}-m_{2}^{2}-(E_{1}^{2}...
user avatar
  • 3,544
1 vote
1 answer
78 views

A very basic question about weighted data

I have a dataset in the form {{A1,B1,C1,...},{A2,B2,C2,...},...} and the weights in the form {w1,w2,w3,...} Having this ...
user avatar
  • 3,544
1 vote
0 answers
64 views

How to generate random points with weight distribution and specific criteria? [duplicate]

Consider some function $f(E_{1},E_{2})$, say $$ \tag 1 f(E_{1},E_{2}) = \exp[-E_{1}^{3}+E_{2}^{2}] $$ I want to generate random $n$ points $E_{1}$, $E_{2}$ using this function as weights, with an ...
user avatar
  • 3,544
3 votes
2 answers
156 views

Is there a way to generate a data-driven Monte Carlo sample from a histogram?

I have a vector with 50 elements. These are values of a random variable. I have represented the data as Histogram[RandomVariable1Histogram]. However, I need to ...
user avatar
5 votes
2 answers
313 views

How can I speed up RandomVariate in the following case?

I would like to generate random values of some parameter with the weight being the Poisson distribution. An important point is that each time I generate the random number I need to consider the ...
user avatar
  • 3,544
3 votes
1 answer
140 views

How to substitute a random function into a solution of a differential equation?

I would like to solve a differential equation including a source term. The source term is a random variable and I model this by creating a list of RandomReal and ...
user avatar
0 votes
1 answer
49 views

How to sample a conditional distribution

Let $X=(X_1,...,X_n)$ denote the multinormal distribution with covariance matrix $\Sigma$. Then $$\texttt{RandomVariate}[\texttt{MultinormalDistribution}[\Sigma]]$$ samples this distribution. Question:...
user avatar
11 votes
1 answer
291 views

Generating random sequence of integers with ordering constraints

I would like to write a Mathematica routine for generating random musical melodies that obey (some of) the constraints of traditional tonal harmony. For simplicity's sake, I'm interested only in ...
user avatar
  • 1,857
6 votes
4 answers
351 views

Generating large quantity of random numbers from an exponential distribution with fixed sum

I am trying to generate a large number (approx. 2 millions) of random numbers from an exponential distribution of the form: $$D(t)=\exp(-3000\, t)$$ The sum of the numbers must be 40. I use the method ...
user avatar
  • 6,114
4 votes
1 answer
177 views

How to randomly shuffle multiple lists of the same length in the same order

If I have a list, I know that I can use the RandomSample function to randomly shuffle the list. However, if I have $n$ lists, each with the same number of elements, ...
user avatar
  • 285
7 votes
9 answers
804 views

Need four random values in a range which total unity

I need to generate four positive random values in the range [.1, .6] with (at most) two significant digits to the right of the decimal, and which sum to exactly 1. Here are three attempts that do not ...
user avatar
  • 579
7 votes
1 answer
878 views

How can I generate the same random number in Mathematica and MATLAB?

As a part of my research studies, I have developed a code which is essentially based on random generation of numbers. The first version of the code was written in MATLAB, however, for some reasons I ...
user avatar
  • 1,159
1 vote
1 answer
84 views

Generate a normalized Haar-random vector

What is the procedure to generate a random qutrit quantum state? That is, I want to generate a $3 \times 1$ vector $u$ such that $u$ is generated by a Haar random $3 \times 3$ unitary $U$ multiplied ...
user avatar
1 vote
1 answer
53 views

Are there any issues/best practices/suggestions when working with a DataDistribution instead of a distribution?

Suppose there is a random variable $X$ that can take on values $-1,0,1$, with probabilities $P(X=1)=P(X=-1)=.25$ and $P(X=0)=.5$. How can I work with such a random variable in mathematica? (Find the ...
user avatar
0 votes
1 answer
170 views

RandomPoint does not return with many region intersections

I am trying to generate random points on an n-dimensional unit sphere that satisfy a number of linear inequalities (a point $v \in \mathbb{S}^N$ has to satisfy $v \cdot x \geq v \cdot x_k$ for all $...
user avatar
0 votes
2 answers
79 views

Antithetic Variates in Monte-Carlo simulations (code taking too long to execute)

I am trying to use the Antithetic Variates method to reduce error in stock price estimates. Essentially, I generate pairs of negatively correlated RV's and use them to simulate stock price. The ...
user avatar
  • 1
1 vote
2 answers
72 views

Random interior points of a demi circle [closed]

I am trying to write a code in Mathematica that allows me to find random points in this half circle by knowing the center and the radius. Each time I test something I find myself with a point out of ...
user avatar
  • 119
2 votes
3 answers
208 views

Random real antisymmetric matrix [duplicate]

Is there a way to create random real antisymmetric matrix in Mathematica. Please see the example of such a matrix.
user avatar
  • 1,163
3 votes
1 answer
127 views

Why isn't RandomPoint evaluating?

Consider the expression RandomPoint@ BooleanRegion[#1 && ! #2 &, {Sphere[{0, 0, 0}], ConicHullRegion[{{0, 0, 0}}, {{1, 1, 1}}]}] This does not ...
user avatar
  • 7,749
0 votes
1 answer
81 views

Simulating electrons passing through a beam splitter for random number generation

I would like to write a program that would simulate the trajectory of an electron/photon passing through a 50-50% beam splitter and depending on which detector the particle is measured, it would ...
user avatar
11 votes
1 answer
516 views

Why do changing the limits of RandomInteger not affect the result?

Recently I noticed (on Windows 10, Mathematica 12.1) that changing the limits of RandomInteger, while keeping SeedRandom fixed, ...
user avatar
  • 974
0 votes
0 answers
39 views

How to generate the low discrepancy Halton sequence in Mathematica and plot it?

Pre-requisite Definition For any integer $n\geq 0$ and base $b \geq 2$ as follows, we define the following function, known as the radical-inverse function, \begin{align} \phi_b(n)=\sum_{j=1}^m a_j b^{-...
user avatar
0 votes
1 answer
48 views

Mean of Randomvariable

I want to calculate Mean[x+y]. x = NormalDistribution[] y = NormalDistribution[] Mean[x + y] ...
user avatar
1 vote
0 answers
53 views

How do I generate a random permutation of a (long [millions-length]) list of symbols? [closed]

I have a list of length twelve: p = {t[1, 1], t[1, 2], t[1, 3], t[1, 4], t[2, 2], t[2, 3], t[2, 4], t[1, 5], t[3, 3], t[3, 4], t[1, 6], t[4, 4]} and a set of ...
user avatar
6 votes
1 answer
105 views

How to generate an heterogeneous mesh

I'd like to generate a mesh with a big variance in cell size. Something like I'd prefer not to rely on a vertex model and perhaps use something simpler, like ...
user avatar
  • 4,138
4 votes
1 answer
182 views

How can I speed up this Monte Carlo integration for the Stieltjes constant $\gamma_n$?

Pre-requisite Definition Stieltjes constants ($\gamma_n$) are the constants that occur in the Laurent series expansion of the Riemann zeta function. $${\displaystyle \zeta (s)={\frac {1}{s-1}}+\sum _{...
user avatar
4 votes
2 answers
290 views

Generate 3 dimensional random vectors

How can one generate a random vector $v=[v_1, v_2, v_3]^T$ satisfying $\sqrt{v_1v_1^* + v_2 v_2^* + v_3 v_3^*} = 1$, where $T$ and $*$ denote the transpose and complex-conjugate, respectively?
user avatar
  • 339
4 votes
2 answers
150 views

How to throw $n$ random noodles of equal length?

I've been meaning to modify some code given in the the Region Disjoint documentation for the Buffon's Needle problem to instead model Buffon's Noodle Problem. In Buffon's Needle problem you randomly ...
user avatar
0 votes
2 answers
85 views

Multinomial Distribution Sampler not working

I am trying to sample from a multinomial distribution many times but with a different multinomial distribution each time. The straightforward ...
user avatar
  • 1
4 votes
2 answers
215 views

Implementation of Bean machine (Galton board)

Bean machine is a triangular array of pegs, Balls are dropped onto the top peg and then bounce their way down to the bottom where they are collected in little bins.Each time a ball hits one of the ...
user avatar
  • 4,910
2 votes
1 answer
99 views

How to generate random variate in custom domain for a distribution?

I have a distribution defined in a particular domain of the variable but now I want to generate a random variable not in the entire domain but only in a subset of the domain. Here is what I'm trying ...
user avatar

1
2 3 4 5
17