Tag Info

Hot answers tagged

7

centers = RandomReal[{0, 10}, {20, 2}]; radii = RandomReal[{0, 1}, 20]; Graphics[{MapThread[{RGBColor@@RandomReal[{0, 1}, 3], Circle@##} &, {centers, radii}], FaceForm[Transparent], EdgeForm[Red], Polygon[{{0, 0}, {0, 10}, {10, 10}, {10, 0}, {0, 0}}]}] Edit If you want disjoint circles you may go with something like: ...


7

Preferential growth with an increasing number of vertices means that older vertices will have far more connections than the newer ones. So we know which vertices will probably be chosen, and we should try to use that in our algorithm. One way to do it is roulette wheel selection: randomChoice = Compile[{{list, _Real, 1}}, Module[{acc, i = 1, r1 = 0., r2 ...


4

This should be much faster than using a loop or mapping: rng = 100000; min = 0; max = 10000; k := 0.5; offsets = RandomInteger[{1, 10}, rng]; randomA = RandomReal[{min, max}, rng]; randomB = RandomReal[{min, max}, rng]; effect = xEffect = Range@rng; us = UnitStep[xEffect - offsets - 1]; nr = Pick[Range@Length@effect, us, 0]; nr2 = ...


2

Like this: computeEffect[xEffect_] := With[{offset = RandomInteger[{1, 10}]}, If[xEffect - offset < 1, RandomValue, randomA[[xEffect - offset]] + k randomB[[xEffect - offset]] ] ] effect = computeEffect /@ Range[1000]; Or effectLength = 1000; diffs = Range[effectLength] - RandomInteger[{1, 10}, effectLength]; computeEffect2[diff_] := ...


1

While David G. Stork's solution works it is not efficient. You are generating all possible tuples and then selecting them randomly. Try this with a list of 19 elements in tuples of 10 and you will be waiting forever. This solution should work just fine with lists of any length list = {a, b, c, d}; Partition[ RandomSample[list] , 2] {{c, d}, {b, a}} ...



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