Tag Info

New answers tagged

8

@Simon Woods points out in a comment that: In fact the delay on the initial run is caused by compiling code to provide the Poisson distribution :-) You can look at ImageColorOperationsDumpiImageEffectPoissonNoise to see how it works internally. Now, although PoissonDistribution can't be compiled, there's nothing stopping the use of my own C++ ...


3

Another way is {#, RandomReal[#]} & /@ RandomVariate[TriangularDistribution[{0, 1}, 1], 1000] To see we do have a uniform distribution: PDF[ TransformedDistribution[{x, y}, { x  TriangularDistribution[{0, 1}, 1], y  UniformDistribution[{0, b}] }] /. b -> x, {x, y}]


5

Generate random pairs, and reverse-sort each one: Sort[#, Greater] & /@ RandomReal[1, {10, 2}] or, for fun, generate two numbers between 0 and 0.5, and add the second to the first: RandomReal[0.5, {10, 2}].{{1, 0}, {1, 1}}


11

RandomReal[1, {100, 2}] /. {x_, y_} /; y > x :> {y, x} The graphics below confirm that you retain a uniform distribution


2

I think the trick is to use the RandomSeed option as shown below: Do[Print[NMinimize[{fourVertIsoHamilt[x11,x12,x13,x14,x21,x22,x23,x24,x31,x32,x33,x34,x41,x42,x43,x44], ...


3

Let us arbitrarily set some details (because they were not specified): Allow all positive integers $\alpha$ and find the probability $p_\alpha$ with which each must be selected so that $\sum_{\alpha=0}^\infty \alpha\, p_\alpha = N$ for given $N$. Applying Jaynes' maximum entropy principle (that Szabolcs mentioned), we find that the "least biased" estimate ...


5

How about... ...making 4 random 'integer cuts' or slicings of the line segment from 0 to n? I used this approach, though more crudely, in an earlier code-golf challenge: http://codegolf.stackexchange.com/questions/8574/generating-n-unique-random-numbers-with-a-specific-sum. (Chenminqi proposed a similar analysis for the present challenge but for some ...


2

Brute force approach, using 9 for a somewhat smaller example: s93 = Select[ RandomInteger[{0, 9}, {10^6, 3}] , Total@# == 9 &]; a look at the statistics of the results: SortBy[Tally[Sort /@ s93], #[[1]] &] {{{0, 0, 9}, 2920}, {{0, 1, 8}, 6048}, {{0, 2, 7}, 5940}, {{0, 3, 6}, 6174}, {{0, 4, 5}, 6067}, {{1, 1, 7}, 2995}, {{1, 2, 6}, 6025}, ...


11

There are much better programming methods in Mathematica than loops. Here is an approach based on IntegerPartitions, it chooses 5 numbers that sum up to 35: RandomChoice[ IntegerPartitions[35, {5}]] {12, 10, 7, 5, 1} If we don't use RandomChoice it will write all 5-tuples, there are IntegerPartitions[35, {5}] // Length 674 of them One ...



Top 50 recent answers are included