Questions tagged [random]

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

Filter by
Sorted by
Tagged with
3 votes
1 answer
56 views

Stochastic process: Understanding Ornstein Uhlenbeck Process

Recently, I have been trying to simulate a random/stochastic variable that follows Gaussian distribution and also has an exponential correlation function $\left\langle X(t)X(s)\right\rangle= e^{-\frac{...
  • 549
0 votes
0 answers
66 views

How to uniformly distribute data points in all the region in a ListLogLogPlot

I've drawn a listLogLogPlot by generating random numbers. But the random numbers are not uniformly generated in all the region. More points are generated in the higher region than in the lower side. ...
2 votes
0 answers
58 views

Solving stochastic equation

I am trying to solve, numerically, a classic stochastic Liouville's equation, namely \begin{equation} \frac{dA(t)}{dt} = -B(t)A(t)+ {\cal C}(t) \end{equation} with $B(t)=\cos(\omega t)$, and ...
  • 549
1 vote
3 answers
129 views

How to randomly generate points in a line?

For example,how to randomly generate 100 points in line L:y=x,and x~N(0,1). Edit:I mean,for point p(x,y),x=t,y=t,t is random variable,and t~N(0,1).Randomly generate 100 points like it.
1 vote
1 answer
43 views

How can I calculate the moments of a truncated random variable?

I am using the Moment function to calculate the moments of an exponential random variable. as follows, Moment[ExponentialDistribution[3], 9] However, I need to ...
4 votes
1 answer
155 views

Why won't my random walk work in a Mathematica Do loop? [closed]

This produces a nice random walk plot: ...
4 votes
1 answer
44 views

Speeding up RandomVariate with custom probability distribution

I have the defined a custom distribution, which is a Gaussian where the exponent can be any real n greater than 0 (set to actually be >0.5 in use), i.e. ...
  • 115
0 votes
1 answer
63 views

How to generate random value under the given distribution fast?

Consider a distribution distr[EN_, Enu_, mN_] = Exp[-(Sqrt[EN^2 + mN^2]/Enu)]*Sqrt[(Sqrt[Enu^2-mN^2]/2)^2 - EN^2] Sqrt[ EN^4 - (Enu/4)^4] where mN is a free ...
  • 4,116
13 votes
1 answer
224 views

How can CompiledCodeFunctions be optimized and parallelized?

Fast generation of random variates as test case The earlier question (195435) about performance tuning with regard to fast generation of random variates for a gamma distribution has stirred my ...
  • 12.6k
1 vote
3 answers
158 views

Weighted random choice from a list

I want to randomly choose one element from a list but preferring elements with small distance from the center of a list. How to do it properly say with normal distribution? I am not good at statistics....
  • 3,840
10 votes
1 answer
633 views

Mathematica or math question: why my own Monte Carlo gives different result from the Mathematica's one?

Consider some function of arguments x,y,z, where the latter have some domain of definition $\mathcal{R}$: ...
  • 4,116
4 votes
1 answer
102 views

How to speedup evaluation of a random point from an implicit region?

Consider three variables s2,t1,t2, and parameters ma,mb,m1,m2,m3,s. The domain of definition for s2,t1,t2 is given by the region Region3Particle: ...
  • 4,116
1 vote
2 answers
123 views

How can I improve this code?

The code below is working well, but it's very slow in the Manipulate box. I know that the Do and AppendTo parts aren't very ...
  • 3,655
1 vote
0 answers
44 views

Is there "absolute" point size for Graphics3D?

I would like to get points size that vary when the viewer is zooming in/out through the 3D graphic. The point size I want should be defined as "absolute", relative to the coordinates used ...
  • 3,655
0 votes
2 answers
59 views

How to add random point size to this distribution of 3d points?

The code below creates a random distribution of points in 3D. Currently, the points have a random size, and the size is the same for all points. I need the points to get individually a random size, ...
  • 3,655
5 votes
1 answer
179 views

How to get fuzzy points in a 3D view?

I would like to produce fuzzy random points (sprites like) in a 3D view. Applying a Blur command doesn't do the trick since the view is then frozen and we couldn't rotate the view anymore, and I don'...
  • 3,655
1 vote
1 answer
94 views

Manipulating a Haar random unitary matrix and computing probabilities

I am new to Mathematica and its many features. Here is a problem that I was trying to model. Consider a $4 \times 4$ Haar random unitary $U$. Define by $|00\rangle \langle 00|$ the following matrix: \...
1 vote
1 answer
124 views

How to introduce random correlations in a 3D uniform distribution of points?

I would like to build a simple visualization of the distribution of galaxies on a large scale model of the universe. Currently, my galaxies are represented as uniform random black dots in a 3D cube, ...
  • 3,655
8 votes
0 answers
134 views

Kernel crash with RandomChoice

Bug introduced in 8.0.4 and persisting through 13.0.1 or later (case: 4948255) I use Mathematica 12.3.1 for Microsoft Windows (64 bit). While playing with some code inspired by this recent question, ...
  • 63.1k
14 votes
2 answers
145 views

Help understanding a bug when FoldList using RandomChoice is Compiled

Bug introduced in 3.0, persisting through 13.1. Preamble: I submitted this bug to support@wolfram.com and it was acknowledged. I assume it will be fixed eventually. In the meantime I'd like to ...
  • 1,549
0 votes
0 answers
46 views

3D Cylinder with uniform distribution in volume

I would like to draw a figure in 3D where I have a cylinder (or ellipsoid) and some spheres in volume with fixed distenced between. I understand how to build a cylinder or Random spheres in cube, but ...
  • 1
5 votes
3 answers
396 views

Generate a 2D random point outside a region [closed]

I can generate a 2D random number within a square region, say $\{x,y\} \in [p_i,p_f]$, using rand = RandomReal[{pi, pf}, 2]; I now would like to get a random ...
  • 727
6 votes
5 answers
821 views

Generate a random number outside a range

Random numbers in a range[pi,pf] can be generated using p = RandomReal[{pi, pf}]; How can I generate a random number from this ...
  • 727
0 votes
0 answers
33 views

Generate a random matrix with a condition on its eigenvalues

I can generate Radom matrices using mat = RandomReal[{-1, 1}, {2, 2}]; But how can I generate the mat matrix so that the ...
  • 727
4 votes
1 answer
100 views

Obtain a group with desired properties using RandomEntity

This is my current try: ...
  • 24.6k
1 vote
1 answer
93 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 (...
  • 69
-1 votes
2 answers
202 views

Random graphs in Poincare disk

The question is inspired by that article ( see Wiki as a first reading on the topic). This is an actual topic of modern mathematical physics. Here is my (partly successful) attempt to implement such ...
  • 18.4k
5 votes
2 answers
481 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 ...
6 votes
3 answers
352 views

I want to count number of points inside the given shape

...
0 votes
2 answers
124 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$. ...
1 vote
1 answer
75 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: ...
  • 173
0 votes
1 answer
52 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 ...
2 votes
2 answers
402 views

How to put a FOR loop in a WHILE loop

I have a strange matrix like this one in the picture Now, my goal is to change all the 1s with random complex numbers of modulus 1, but if the element $a_{12}=z$, then $a_{21}= \bar{z}$, so the ...
  • 123
0 votes
2 answers
60 views

Random Variate inside a function causing the function to behave unexpectedly

I define a Random Variable drawn from a custom probability density. ...
0 votes
1 answer
174 views

Random figures in the matrix

Consider the matrix 'm1' : m1 = RandomReal[{0, 1}, {100, 100}]; Let's pick one of the elements of this matrix. It will be the center (point of intersection of the ...
  • 969
3 votes
3 answers
269 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, ...
  • 6,675
3 votes
3 answers
148 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 (...
  • 383
4 votes
2 answers
164 views

RandomReal vs Random[Real

Let's say I need random numbers with increasing precision to simulate a particular function, so I try: ...
  • 19.1k
12 votes
3 answers
479 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 ...
  • 123
2 votes
2 answers
94 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 ...
0 votes
1 answer
51 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 <...
  • 249
5 votes
2 answers
274 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, ...
0 votes
1 answer
76 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 <...
1 vote
0 answers
57 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(\...
1 vote
0 answers
40 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 ...
4 votes
2 answers
99 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, ...
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}...
  • 4,116
1 vote
1 answer
80 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 ...
  • 4,116
1 vote
0 answers
67 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 ...
  • 4,116
3 votes
2 answers
157 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 ...

1
2 3 4 5
17