Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [random]

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

5
votes
2answers
207 views

Record Statistics for Discrete Random Walks

I code a random walk of length 100 drawn from a LaplaceDistribution: Accumulate[RandomVariate[LaplaceDistribution[0, 1], 10000]] I am having trouble counting the ...
1
vote
2answers
96 views

Sampling data from numerical values of density distribution of nucleons

How could i sample my data which follows distribution if i have only numerical values of density distribution as an example data attached as in picture I tried but do not know how to do it. The data:...
0
votes
1answer
43 views

2d-RandomWalks with N steps and fixed distance between first and last point

community, I'm trying to figure out a way how to create a 2d list simulating a N-Step-Randomwalk with a fixed distance between first and last point. I already got the RandomWalk with the step size 1: ...
5
votes
0answers
68 views

Random number generation within Compile and Parallelization->True

According to this thread RandomChoice is a compilable function. I use it to generate random numbers in a compiled function with parallelization enabled. I wrote ...
4
votes
6answers
311 views

Randomly distribute numbers to lists

I have 4 empty lists. I would like to randomly distribute numbers from 1 to 10 to these 4 empty lists. How can I add integers to lists randomly? For example: ...
3
votes
3answers
228 views

Sum of Random Integers

I am trying to get a list of numbers with at least 1000 sums as possible, using random numbers from 1 to 10. But I don't want to get blank list output. How can I only get a list of numbers greater ...
0
votes
3answers
33 views

How to create 2 lists of RandomIntegers based on condition?

How do i create 2 lists of RandomIntegers that are the same at certain points based on a condition. For example there are three lists: List A List B List C List C already exists. I am trying to ...
2
votes
0answers
74 views

How to match random number generator to R?

Although I know the algorithm that R is using for pseudo-random numbers I am unable to match the generation of random numbers. ...
3
votes
1answer
115 views

Generate a smooth random function (2D curve) with endpoints specification?

Here is a PDE example, adapted from Wolfram Documentation: ...
1
vote
1answer
36 views

How to select random number of elements from a list?

Assume that I have a list a = {1,2,3,4,5,6}; and I want to have a function that outputs a subset of the list such that with probability p=0.2 each element will ...
0
votes
0answers
52 views

Random points from an image using a BernoulliDistribution

I am a Mathematica newbie. I need to sample random points from an image which I have stored in a variable img as: ...
0
votes
1answer
93 views

Why does Monte Carlo integration underestimate my integral as integration range increases?

I'm having a huge problem with Monte Carlo integration. This simple example adequately shows the problem. ...
2
votes
1answer
45 views

Matrix Randomization

Is there a way to take a 20x20 array and replace 2 random parts of this array with a 2x2 matrix? I've tried rvalues = ConstantArray[r, {20, 20}]; to make the ...
0
votes
1answer
55 views

Negative values with RandomVariate

I am using the following code to generate some random number from a custom distribution: ...
0
votes
1answer
44 views

Am I using RandomVaraite and ProbabilityDistribution correctly?

The following code does not produce an output on my Mma (version 11.3 for Windows) ...
6
votes
2answers
132 views

How can I get new random values with each blank in ReplaceAll?

Is there any way to get different values for different blanks with ReplaceAll[]? For example, I would like to do something like: ...
16
votes
3answers
1k views

Efficient way to simulate thousands of Markov chains

I am currently trying to simulate relaxation of a protein population while maintaining the stochastic properties of the system. For this, I used a Markov chain to describe the temporal evolution of ...
6
votes
3answers
227 views

How can I delete a random part of an expression?

I have the expression: Times[0.19157500241430547,Power[Plus[0.7235014213631388,k,Times[-1,Power[m,c]]],Times[g,z]]] Also represented as: ...
5
votes
3answers
145 views

Improving the run time of random walk simulation

One of our professors told us that during his thesis he used Mathematica in simulating it since it is about networks, I don't know how he did it but all I know is he said it took about two weeks to ...
4
votes
3answers
116 views

Construct Distribution Histogram From Random Variable

Given a Beta Random Variable $X$ with parameters $\alpha, \beta$ and a positive constant $n$, suppose I am interested in the distribution of: $$Y:=\lfloor nX\rfloor$$ Suppose I want a histogram ...
2
votes
1answer
66 views

Apply RandomReal to list in list in Mathematica

I have a big list: {{1,1,1},{1,1},{1,1,1,1,1,1,1}....{1,1,1,1}} How can I apply RandomReal to every single element in the list?
11
votes
5answers
484 views

Evenly spaced points on boundary of polygon

I have a polygon and I would like to generate $n$ evenly spaced points along the boundary.
2
votes
1answer
75 views

Acceptance Rejection Method

I need to generate a random number (real) and then test if this number works on my pdf. if it works i append it to a list. if it doesn't, i reject it. Until now i have done this: ...
3
votes
0answers
57 views

Generating random coordinates (3D) with constraint

I have been trying to generate random $(x,y,z)$ coordinates (i.e. for 15 ellipsoids) so that they obey following constraints: ellipsoid's length is constant, ellipsoids do not intersect (fulfilled ...
3
votes
2answers
86 views

Optimize RandomVariate for a $1/x^4$ distribution

I'm working with the following code, where I define a probability distribution proportional to $1/x^4$. ...
0
votes
1answer
80 views

Generate random point on the external surface of this complex geometry

This is a followup to this question of mine. How do I generate a random point on the most external surface of this complex geometry? ...
1
vote
0answers
27 views

How to ask FindClusters to return the loss function value in the output?

I have some data points pts as below:- pts = BlockRandom[SeedRandom[123]; RandomReal[1, {100, 2}]]; Now I want to separate ...
4
votes
2answers
164 views

Generate “nice” random matrix

I don't frequent this community so please give criticism if this is a poor question. I am trying to make a tool which generates a small (say, $4\times 4$) matrix with integer entries which has a "...
1
vote
0answers
90 views

Bizarre error messages when monitoring random integers

I am doing tbl = {}; Monitor[ Do[AppendTo[tbl, RandomInteger[{1, 100000}, 2]], 100000], Length[tbl] ] (well in fact I am doing something less boring but what I ...
3
votes
1answer
62 views

How to generate a random real under a specified density function?

I want to generate a random real in the interval [0,1] according to the density function f(x) = 2x.
5
votes
1answer
384 views

Random walk in one dimension — meeting of two particles

I'm new to Mathematica and still teaching all by myself, hope you bear with me. I have the code: ...
1
vote
0answers
32 views

RandomVariate with a custom distribution [duplicate]

I have a customized distribution and I have to draw some random number from it. How do I use RandomVariate to draw random number from a custum distribution? My naive attempt ...
6
votes
3answers
231 views

Generate a random pattern with at-most n repeated consecutive elements

I want to generate a random pattern which has at-most n (>= 0) repeated consecutive elements from a sample space. The following example explains what I mean: ...
1
vote
1answer
55 views

Getting PDF from imported Histogram

So I'd like to create a probability density function from an existing histogram from a program that I use. My input data is of the form ...
3
votes
1answer
101 views

Sampling “Random” Cyclic / Acyclic Graphs

This is an extension of RandomGraph with specific constraints Where @Histograms wanted to make $n$ random graphs with a specific constraint (in @Histogram's case, having 2 vertices each with exactly ...
5
votes
3answers
121 views

Uniformly distributed numbers fulfilling conditions

I would like to generate 10 random lists of four elements (t, l, p, ...
14
votes
5answers
597 views

Smarter Shuffle of a List

I have a 2D matrix representing a keyboard: ...
7
votes
2answers
1k views

Can this code be changed to run faster?

I've worked for several days trying to get this code to run faster. The imported data is 15MB. ...
2
votes
1answer
36 views

Evaluation Time of RandomVariate Function

This question is about the runtime of the function RandomVariate. Take a simple normalized Gaussian distribution G on the real line, I tried to generate N random ...
0
votes
0answers
34 views

Finding vectors admitting to the same value of a given function

Given a vector function $f(\vec{v})$ where say $\vec{v}=(x,y,z)$ is a $3$ dimensional vector. How does one find a large number of random $\vec{v} \in \mathcal{W}$ from a region $\mathcal{W}$ that ...
8
votes
3answers
91 views

Creating a random matrix of no duplicates in both row and column from a given set list of elements

Say I have a list of letters {A,B,C,D,E,F,G,H}, I want to create an $4\times 8$ array where each row must not contain duplicates and each column must also not contain duplicates. Naively writing: <...
2
votes
1answer
109 views

Is a probabilistic primality test implemented in Mathematica?

Imagine that I need to verify that a specific integer, like $n = 10^{1347}+3049$ is prime. ProvablePrimeQ takes a lot of time, and, even if it will eventually work ...
7
votes
2answers
441 views

Creating a less random list

I'm trying to create an list like {1,3,2,5,8,7,9}, or {2,1,5,6,4,7,9}, that the elements in each list is sorted in a rough order,...
4
votes
1answer
98 views

Random particle motion

I have a foundational function that allows me to simulate particles moving in a box according to some movement function. The code is here: ...
1
vote
0answers
45 views

Looking for a way to run through every time step of a cellular automaton function with random seeds

I have been creating 2D cellular automaton functions in Mathematica and I would like the output to be a graphical representation of the array at each time step. I know I can do this with ListAnimate: ...
7
votes
1answer
151 views

Getting random points on a mesh region

So I have a region defined by a MeshRegion,like ...
5
votes
1answer
66 views

Random normalised variable generation

I want to generate 8 random variables (in reality to form 4 complex numbers) such that the sum of the 8 variables squared is equal to unity. The aim of generating such numbers is to perform a quantum ...
2
votes
4answers
116 views

How do I use the values generated in a for-loop in my first iteration to my next iteration?

This one is somewhat hard to explain, but I'll try my best to. I'm trying to generate a list of numbers (containing only pi/10, 0, -pi/10). Numbers are randomly selected from these 3, where the ...
0
votes
1answer
69 views

Defining a random potential on the unit square

I'm trying to define a random potential on the 2D unit square. For some fixed j, I want to decompose the unit square into $2^{2j}$ smaller squares with sides length $2^{-j}$. On each of the smaller ...