Questions tagged [random]

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

Questions about random number generation and the properties of numbers so generated. Questions about how to generate different types of random numbers or lists of them (RandomReal, RandomInteger, RandomComplex and RandomPrime), how to sample populations (RandomChoice and RandomSample) or how to sample symbolic distributions randomly (RandomVariate). Also questions about how to initialize, block, reinitialize or modify the pseudorandom number generator of Mathematica by using SeedRandom and BlockRandom.

Useful links:

893 questions
61
votes
3 answers

Quality of random numbers

Mathematica has several ways of generating random numbers: Congruential, ExtendedCA, Legacy, MersenneTwister, MKL, ParallelGenerator, ParallelMersenneTwister, Rule30CA. For Method -> "Congruential" the page notes that this generates low-quality…
Charles
  • 1,359
  • 8
  • 13
18
votes
1 answer

Mathematica giving infinity as a random number!

I am trying to generate several random numbers from normal distribution using Mathematica. The following is the relevant code: Clear["Global`*"]; SeedRandom[8396] Sigma = 1; Dim = 4; A = RandomReal[NormalDistribution[0, Sigma], Dim, …
dbm
  • 1,239
  • 7
  • 21
17
votes
1 answer

Compare C++ Standard Library's Mersenne Twister with Mathematica's Mersenne Twister

The C++ standard library does contain a set of random distribution classes, among other things a Mersenne Twister engine. What I'd like to do is to generate the same random number distribution, using the same seed for C++ and Mathematica. For…
Stefan
  • 5,347
  • 25
  • 32
13
votes
11 answers

Random numbers that sum up to specific value

I would like to generate a list with random numbers, which add up to a specific value. While[Total[x] == 28, x = RandomInteger[{0, 28}, 5];Print[x]] The random number list should be returned if their sum is 28. Unfortunately, this loop does not…
Bimmel
  • 573
  • 3
  • 13
12
votes
1 answer

Does `SeedRandom` give the same set of random numbers across operating systems?

If I use SeedRandom[12345] RandomReal[{0,1},100] I get the same random numbers on two versions of Mathematica: 10.4.1.0 on Windows 10 and 11.1.1.0 on Windows 7. But does the same seed get the same set of random numbers on OS X and flavors of…
JimB
  • 41,653
  • 3
  • 48
  • 106
11
votes
2 answers

What will happen, if I don't specify random seed by SeedRandom function?

Suppose I want to run several times of the same code containing RandomReal function, but I don't initialise the random seed. What will happen? I tried, but each time the RandomReal[] return different values, does it mean that Mathematica using some…
LifeWorks
  • 427
  • 2
  • 11
11
votes
3 answers

Generating unique random number lists

I am new in programming. I have an array containing, let's say 20 elements and first I want to randomly select two elements from it and record them. Then I will select two elements from the array of twenty elements again and record them. The process…
Daniel
  • 319
  • 6
  • 12
11
votes
1 answer

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, does not affect the result and produces a weird non-random non-pseudo random pattern. For…
Hans Olo
  • 1,843
  • 2
  • 9
  • 15
11
votes
2 answers

How to generate a random integer array satisfying complex constraints

I want to generate several random arrays {x1,x2,x3,x4,x5} that satisfy the following complex constraints: (2.3 x1 + 4.1 x2 + 2.2 x3 + 3.5 x4 + 1.8 x5 <= 50) && (0 <= x1 <= 5 && 0 <= x2 && 1 <= x3 <= 5 && 1 <= x4 && 0 <= x5 ) && (2 <= x3 + x4 <=…
user69323
10
votes
2 answers

Have the Random functions changed?

I re-ran a program I wrote for Mathematica v8, now on v9, and it appears to generate different RandomInteger numbers, even though I use the same SeedRandom at the beginning. Have Random functions changed in v9?
stevenvh
  • 6,866
  • 5
  • 41
  • 64
10
votes
5 answers

How to generate random points without duplication?

In generating a list of random 2D integral coordinates e.g. {{u1,v1}, {u2,v2}, {u3,v3},...}, how can one write a condition specifying that no point is repeated, i.e no {ui,vi} == {uj,vj}?
spaced
  • 235
  • 1
  • 8
9
votes
3 answers

A deterministic function to generate a random number

Using Mathematica, I need to define a function of one integer variable that generates the same real number in the range 0 to 1, if it is called with the same argument, but gives a different real number if its argument is changed. For example…
Cham
  • 4,093
  • 21
  • 36
8
votes
0 answers

Restarting random number generators where you left off

I have code that uses both RandomReal and RandomInteger a number of times to produces a sequence of $n$ data sets. After closing the notebook and quitting the kernel, I would like to be able to start the code where I left off in the random…
user26718
  • 366
  • 1
  • 2
8
votes
2 answers

Random walk with fixed initial and final coordinates and the length

Looking at the problem of a random walk in 2D or 3D, I would like to generate several trajectories that start all in some starting point, say, (0,0) in 2D and (0,0,0) in 3D and end up all in a specified point, say (20,20) in 2D or (20,20,0) in 3D…
Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96
7
votes
2 answers

Obtain the current value of the seed used by the random number generator

I would like to be able to do something like the following pseudocode: SeedRandom[someNumber]; (* Initialize the random number generator's seed for reproducible results *) Do Run a batch of Monte Carlo simulations; Obtain the current value…
Matt
  • 453
  • 2
  • 13
1
2 3 4 5 6