Questions tagged [random]

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

Filter by
Sorted by
Tagged with
-2
votes
0answers
30 views

If statement based on outcome of RandomChoice

Been doing a school project, where I am asked to simulate a roulette wheel with 18 Red tiles, 18 Black tiles and 2 Green tiles. The individual in the scenario bets $n on 'Red'. If the wheel lands on ...
11
votes
1answer
278 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 ...
6
votes
4answers
292 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 ...
4
votes
1answer
128 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, ...
7
votes
9answers
751 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 ...
7
votes
1answer
810 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 ...
1
vote
1answer
32 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 ...
1
vote
1answer
50 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 ...
0
votes
1answer
132 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 $...
0
votes
2answers
63 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 ...
1
vote
2answers
64 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 ...
2
votes
3answers
167 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.
3
votes
1answer
115 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 ...
0
votes
1answer
67 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 ...
11
votes
1answer
512 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, ...
0
votes
0answers
32 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^{-...
0
votes
1answer
43 views

Mean of Randomvariable

I want to calculate Mean[x+y]. x = NormalDistribution[] y = NormalDistribution[] Mean[x + y] ...
1
vote
0answers
43 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 ...
6
votes
1answer
86 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 ...
4
votes
1answer
153 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 _{...
4
votes
2answers
223 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?
4
votes
2answers
140 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 ...
0
votes
2answers
55 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 ...
4
votes
2answers
157 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 ...
2
votes
1answer
85 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 ...
1
vote
0answers
56 views

Stochastic noise with known propability density function

How can I generate samples for random function, which functional "probability density" is known? When I say "probability density" for random function $\xi(\mathbf{q},t)$, I mean, ...
2
votes
1answer
108 views

Creating random differential equations

I'm working on an educational project and new to Mathematica Language. Can I create,like multivariance equations with different f[x] in y'[x]=f[x] by using one function? The output should be like this:...
0
votes
1answer
36 views

Simulating jump Markov process

I am trying to simulate a jump Markov process as follows. I define the process $N_j = N_{j-1} + 1$ with probability 1/2 or $N_j = N_{j-1} - 1$ with probability $1/2,$ with $N_j = 0$ as an absorbing ...
0
votes
1answer
61 views

Ndsolve of random (periodic) initial conditions via BSplineFunction

Suppose we want to solve the heat equation for a random initial temperature field T(t,x,y). Therefore I define the initial conditions with the BSplineFunction which nicely incorporates periodic ...
1
vote
2answers
74 views

Creating a list of $xy$ pairs

How do I create a list of $xy$ pairs of points where the $x$ points are evenly spaced between a given range with a specific step size, and the $y$ points are given by a function, but with some random ...
1
vote
2answers
37 views

Replace points on a grid with numbers to maintain order

I am DMing a game of DnD and one of my players is really into fear effects, which is cool, but the effect of having monsters suffer from the "panicked" condition gets tedious to render via ...
0
votes
2answers
121 views

Drawing the filled Julia set of a polynomial

Suppose I use JuliaSetPlot to draw the Julia set of a polynomial. Is there a way, assuming the set is connected, to fill in the region? My idea was to use ...
1
vote
1answer
51 views

How to generate a random matrix with arbitrary correlation between elements?

I would like to find a smart way to generate a $N\times N$ random matrix $M$ with arbitrary correlation: \begin{equation} \boxed{\langle M_{ij}M_{kl}\rangle=\tau_{ijkl}} \end{equation} Where the mean ...
8
votes
2answers
154 views

Efficient uniform sampling of certain Boolean matrices

I want to uniformly sample $(0,1)$-matrices with certain constraints. In particular, I want sum of each row to be rowsum and the sums of columns to equal ...
0
votes
1answer
85 views

How to generate randomly points that belong to the given range?

Consider some rectangle called ExperimentLocation, and a circle ParticleAzimuthalCoverage: ...
0
votes
1answer
51 views

Random composite integer n with 200 digits and Miller-Rabin witnesses [closed]

I wanna take a random composite integer n with 200 digits and check how many, out of 100 random integers, that are Miller-Rabin witnesses for compositeness of the integer n. The first thing I need to ...
2
votes
2answers
70 views

Calculate the Viswanath's constant (Random Fibonacci sequences)

How Can I calculate first few digits of Viswanath's constant? Viswanath’s constant ≈ 1.1319882487943 is a real number whose nth power approximates the absolute value of the nth term of some random ...
3
votes
1answer
92 views

How to create random isolated clusters periodically?

Let's assume we have a $n \times n$ grid repeated periodically, and I want to create some random isolated patches on it (and assign some value to those grid points). For a simple example consider this ...
0
votes
0answers
75 views

Function to determine number of trees surviving forest fire [duplicate]

How can I write two functions, each of which have as their argument an array mat of 0s (no trees), 1s (trees), 2s (burning trees), that can determine the trees that survived a forest fire, which run ...
3
votes
1answer
46 views

Problem getting values from a 2D array. Possible problem of denoting variables?

I am trying to setup a system of 100 coins. All the coins are starting off as heads (0). flips = Array[0, 100]; tails = Array[0, 100]; heads = Array[0, 100]; I ...
3
votes
2answers
265 views

Generate symmetric random tensor

I would like to generate a table $T$ of random values of rank $p$ such that my table is fully symmetric: If I swap any indices I get the same value. For example when $p=3$ I would like $T_{ijk}$ to be ...
6
votes
2answers
222 views

Function to create random matrix, then a simulation. *EDIT* Create two functions

How can I write a function with parameters b, i, and j, which would return a i x j array of 0s, 1s, and 2s, but the array needs to be populated randomly with 0s and 1s which have respective ...
0
votes
2answers
60 views

Generate random numbers in such a way that their combinations meet the specified conditions

We need to generate 5 numbers $\alpha,\beta,p,q,k$ so that they meet the following conditions: $\alpha,\beta,p,q,k>0$ $k \cdot p <1$ $k \cdot q >1$ Edit: I think, that this code may be ...
0
votes
1answer
67 views

Numerical simulation

I want to generate a numerical simulation in table for an equational output. I have used following code. But somehow I can't get any output. I am very novice to Mathematica. Can anyone please ...
0
votes
1answer
28 views

Random Walk under a Uniform Distribution

...
3
votes
1answer
57 views

Random walk based on uniform distribution

...
1
vote
0answers
56 views

A Random walk with gaussian step

...
5
votes
2answers
491 views

2-dimensional random walk

b = RandomVariate[NormalDistribution[0, 1]]; ListlinePlot[b, PlotRange -> 35] I am so new to Mathematica. I am trying to generate a 2-dimensional walk with ...
3
votes
2answers
150 views

Replacing a random ith row and column from a matrix

Currently I am trying to delete a randomly-chosen $i^{th}$ row and column from a square $n \times n$ matrix $A$. So far I come up with the following code: ...
0
votes
2answers
101 views

How to generate random vectors without repetition?

Say we have three elements, 0,1,2 and we want to generate 1000 random vectors of length 7 with these elements, i.e. {2,1,0,0,0,0,2} How can we do this without ...

1
2 3 4 5
16