# Tag Info

16

Perhaps have a look at DiscreteMarkovProcess using an appropriate transition matrix embedding your constraints? Here's a simple example, implementing 1-5 above, to get you started: transitionMatrix = { {0, 0, 1/2, 0, 1/2, 0, 0}, {6/10, 0, 4/10, 0, 0, 0, 0}, {1/2, 0, 0, 0, 1/2, 0, 0}, {0, 0, 1, 0, 0, 0, 0}, {1/2, 0, 1/2, 0, 0, 0, 0}, {0, 0, ...

0

(not a Mathematica answer) What you are looking for is impossible from a probability point of view. Either you draw a fixed-size i.i.d. sample from some distribution and you have no guarantee on the sum, or you set the size of you sample and its sum but you skew the distribution. Even if you do not set the sample size in advance and generate a sample until ...

8

@BobHanlon is on the right track with the ErlangDistribution. First we figure out how to generate a value for $x_1$ given that the sum of the $n$ independent exponential distributed random variables is 40. We have independent random variables $x_1\sim Exponential(\lambda)$ and $\sum_{i=2}^n x_i \sim Erlang(n-1,\lambda)$ and we want to find the conditional ...

2

2 million random exponentially distributed numbers with $\lambda=3000$ aren't hard to generate, but their sum is very likely going to be more than 40. So you'll have to settle for fewer numbers - like around 120,000 : SeedRandom; nums = RandomVariate[ExponentialDistribution, 2*10^6]; pos = First@FirstPosition[Accumulate@nums, x_ /; x > 40] (* ...

4

dist = ExponentialDistribution[λ]; Assuming that the random variates are independent, the distribution of the sum of exponential variates is given by the ErlangDistribution Table[TransformedDistribution @@ {Sum[ x[k], {k, n}], (x[#] \[Distributed] dist) & /@ Range[n]}, {n, 2, 7}] {ErlangDistribution[2, λ], ErlangDistribution[3, λ], ...

6

Assuming your lists (let's call them list1 and list2 each have 100 items, then: order = RandomSample[Range]; list1[[order]] list2[[order]] (see the documentation for Part)

1

You could useDirichletDistribution For example: rv = Select[{##, 1 - Total[{##}]} & @@@ RandomVariate[DirichletDistribution[{1, 1, 1, 1}], 100000], Min[#] > 0.1 && Max[#] < 0.6 &]; Illustrating the truncated region alluded to in other posts for first three components: Show[ListPointPlot3D[rv[[All, {1, 2, 3}]], PlotRange -&...

2

I don't think anyone has yet tried FindInstance: FindInstance[{a + b + c + d == 100 && 10 <= a <= 60 && 10 <= b <= 60 && 10 <= c <= 60 && 10 <= d <= 60}, {a, b, c, d}, Integers, 2, RandomSeeding -> Round@(10^6 RandomReal[])] If only 1 result is requested, then the result seems to always be {60,20,...

5

RandomSample[IntegerPartitions[100,{4},Range[10,60]]/100.,1]

-2

If the four numbers are to add to 1, then only three of them can be 'random'. In:= sim = {1, 1, 1}; While[6/10 > Total[sim] || Total[sim] > 9/10, sim = RandomReal[{1/10, 6/10}, 3, WorkingPrecision -> 2] ] In:= sim Out= {0.18, 0.37, 0.23} In:= res = Append[sim, 1 - Total[sim]] Out= {0.18, ...

1

By default, Mathematica appears to use the "MethodOfMoments" method to calculate ARProcess parameters. This is involves calculating the lagged auto-covariances of the input data. However, these are likely calculated by calling the Mathematica "CovarianceFunction" function. The definition given for the covariance calculation (under "...

1

Building on @kglr's response—the way to do this is to incorporate some of the additional constraints into the definition of the region from which sampling occurs (it is a bit more complicated than a Simplex). We can define a region where the 3 variables go over the appropriate range. The implicit fourth variable means that the sum of the 3 cannot be less ...

-2

Strategy: Offset the target value range by 0.1 Generate 4x random values in the range [0-1] Rebase range based on sum of values generated Rebase values to reflect offset (0.1) x4 values => 0.6 Round to 2 digits (excepting floating point error) Array(4).fill(0).map(X=>Math.random()).map((X,ii,A)=>0.1 + (Math.round((100*X/A.reduce((C,I)=>C+I, 0.0)...

4

SeedRandom list = {##, 1 - +##} & @@@ Round[RandomPoint[Simplex, 10], .01]; Grid[Prepend[{"4-tuple", "total"}][{#, Total@#} & /@ list ], Dividers -> {False, {True, True, {False}}}]

2

Use Normalize to find a list of random values between 0.1 and 0.6, which are rounded to two decimal places, and that total to 1. rr = 0; While[Total[rr] != 1, rr = Round[Normalize[RandomReal[{.1, .6}, 4], Total], .01]] The random values are returned as rr. For example: SeedRandom; rr = 0; While[Total[rr] != 1, rr = Round[Normalize[RandomReal[{.1, ....

10

Because you have very tight constraints, the number of allowed points is not very large, so you can generate all of them and then sample. list = Flatten[ Table[If[10 <= (100 - i - j - k) <= 60, {i, j, k, 100 - i - j - k}/ 100., Nothing], {i, 10, 60}, {j, 10, 60}, {k, 10, 60}], 2] Length@list (* 38831 *) RandomChoice[list] (* {0.17, 0.14, 0.4, ...

16

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 the MATLAB version. In which case, you might use something like Mathematica Module[{seed = 123456789}, random := With[{a = 69069, b = 1}, seed = Mod[a seed + ...

Top 50 recent answers are included