Skip to main content
48 votes

How to sample points randomly below a curve?

There is no need in filtering out random points in a rectangle that don't fall in the prescribed region. The sampling within a region can be done directly with ...
corey979's user avatar
  • 24k
26 votes
Accepted

Efficient way to simulate thousands of Markov chains

While the other answers focus on circumventing the simulations, I focus on how to speed up the simulations themselves. (Sometimes, simulations might be unavoidable.) In this situation, when calling <...
Henrik Schumacher's user avatar
26 votes
Accepted

Sisyphus Random Walk

We can iterate with FoldList: data = {0, 1, 1, 0, 1, 0, 1, 1, 1, 1}; FoldList[#2 * (#1 + #2)&, data] ...
Greg Hurst's user avatar
  • 36.4k
25 votes
Accepted

How to sample points randomly below a curve?

As noted in my comment, one approach is as follows. First, generate thousands of pairs of random numbers in the range {0, 2 π}, ...
bbgodfrey's user avatar
  • 61.8k
25 votes
Accepted

Implementing a planetary terrain generation algorithm

Here my two cents. I observed that the major part of the computation is about multiplication. Hence I transformed to logarithms such that we can use summations which can be executed efficiently with <...
Henrik Schumacher's user avatar
24 votes

Implementing a planetary terrain generation algorithm

I have a basic implementation of this which I use with the output of DiscretizeGraphics: ...
b3m2a1's user avatar
  • 47k
24 votes

New Compiler Technology in V12

I wanted to look into this for a long time, and it took only 2 months to come back to this question. To answer your main question: Yes, it appears that the new compiler only supports uniformly ...
halirutan's user avatar
  • 113k
20 votes
Accepted

Generate randomly sized non-overlapping disks?

Just a quick modification of the code here, ...
Jason B.'s user avatar
  • 69k
20 votes
Accepted

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

I'm pretty sure this is expected. Consider the following implementation of RandomInteger: ...
Lukas Lang's user avatar
  • 34.2k
19 votes

How to sample points randomly below a curve?

More of a first principles approach, use the function as a PDF to generate random x data, then for each ...
george2079's user avatar
19 votes

Smarter Shuffle of a List

You may Flatten the list and then take a RandomSample before partitioning to the original dimensions with ...
Edmund's user avatar
  • 42.4k
19 votes

Is there a way to randomly distribute points within a circle on the surface of a sphere?

You can intersect the sphere and a cylinder, and then use RandomPoint. For example, here is a random point on the sphere: ...
Carl Woll's user avatar
  • 131k
19 votes

How to create a random zonogon?

We can using Minkowski Sum (RegionDilation) of any Line's from the fixed point ...
cvgmt's user avatar
  • 77k
19 votes
Accepted

Reproducing Heinrich Heidersberger's Rhythmograms

A starting point We use two variables {u,v}: a parametric form of Mobius Strip f[u,v] and product with some factors to ...
cvgmt's user avatar
  • 77k
18 votes
Accepted

Is RandomGraph really random?

Indeed there are four graphs with 5 vertices and 7 edges, two of which have a Hamiltonian cycle: ...
Sjoerd C. de Vries's user avatar
18 votes
Accepted

Random points around the given curve

Using RandomPoint[] with TubeMesh[] (routines from here and here) does the job: ...
18 votes

Efficient way to simulate thousands of Markov chains

I essentially derive a second distribution - without a need for stochastic modelling - from DiscreteMarkovProcess timeslices according to your state to value ...
kirma's user avatar
  • 19.1k
17 votes

RandomChoice output isn't packed

In order for RandomChoice to produce a packed array, the RHS of the rule needs to be packed: ...
Carl Woll's user avatar
  • 131k
16 votes

Probability of an event

Using built-in statistical functions (Discrete Univariate Distributions). sampleBernoulli[p_, n_] := RandomVariate[BernoulliDistribution[p], n] Then ...
Edmund's user avatar
  • 42.4k
16 votes

Efficient way to simulate thousands of Markov chains

In general, Mathematica is not always the best tool for this type of simulation. That said, you do not need to compute sample paths to compute the mean or variance. For a Markov chain with ...
overfull hbox's user avatar
16 votes
Accepted

On random numbers extracted from NormalDistribution by two different methods under the same seed

I think this is due to the Box–Muller transform that is employed to generate pairs of normally distributed values. This method is much faster than using the inverse commulative probability function. ...
Henrik Schumacher's user avatar
16 votes
Accepted

How to generate a random integer array satisfying complex constraints

...
kglr's user avatar
  • 398k
16 votes

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

If it is solely for regression testing, the quality of the random numbers doesn't matter very much. You can substitute a better random number generator once you know the Mathematica version matches ...
mikado's user avatar
  • 16.8k
16 votes

Generating random sequence of integers with ordering constraints

Perhaps have a look at DiscreteMarkovProcess using an appropriate transition matrix embedding your constraints? Here's a simple example, implementing 1-5 above, to ...
George Varnavides's user avatar
15 votes

Generating animations of clouds with Mathematica

Nice cloud-like images can be generated by summing "octaves" of any of a number of continuous noise functions. Perlin noise is one possibility, as mentioned in the OP; here, I'll present a slightly ...
J. M.'s missing motivation's user avatar
15 votes
Accepted

Probability a random triangle on a circle contains the origin

Some issues with your code are that the list of random data you generate is not a PackedArray; moreover creating random numbers is more efficient if you generate ...
Henrik Schumacher's user avatar
15 votes

Better random (unique) file name

It might be best to use CreateUUID. CreateUUID[] "73ccc27c-687f-4eca-8214-ceeb8a8b7773" ...
Greg Hurst's user avatar
  • 36.4k
14 votes

Generating random points on a Klein's bottle

There is a function for this since Mathematica 10.2. ...
C. E.'s user avatar
  • 70.8k
14 votes

Generate a random number outside a range

You can use RandomPoint with Interval: First @ RandomPoint[Interval[{1, 3}, {5, 7}]] 5....
Carl Woll's user avatar
  • 131k
14 votes
Accepted

How can CompiledCodeFunctions be optimized and parallelized?

In general, the weak spots of interpreted languages are loop constructs and function calls. So I'd suggest to push also the Table into the compiled code to generate ...
Henrik Schumacher's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible