# Tag Info

## New answers tagged random

1

The condition that n[t] cannot fall below zero is an inherent part of a solution algorithm that is applied for a numerical SDE solution and preserves a positivity of solution domain. Typically, such problem is solved by using of implicit numerical solution. Currently, Mathematica has a support only for explicit methods for ItoProcess command (the brief ...

1

If I had interpreted you correctly, here's my attempt to do the figures here: n = 269; k = 10; mat = RandomVariate[GaussianUnitaryMatrixDistribution[n]]; eig = Sort[Eigenvalues[mat], LessEqual]; {p, q} = MinMax[eig]; h = (q - p)/k; bins = BinLists[eig, {p, q, h}]; zer = Im[N[ZetaZero[Range[n]]]]; {zp, zq} = MinMax[zer]; zh = (zq - zp)/k; zbins = ...

0

ZYX[s_String] := Module[{ c = Characters@s, p = Span @@ Sort@RandomInteger[{1, StringLength@s}, 2]}, c[[p]] = Reverse@c[[p]]; StringJoin@c] ZYX @ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "APONMLKJIHGFEDCBQRSTUVWXYZ"

2

randomStringReverse[s_String] := StringReplacePart[s, StringReverse @ StringTake[s, #], #]& @ Sort @ RandomInteger[{1, StringLength @ s}, 2] str = "FDSRTYNHFNKHLIUHG"; newStr = randomStringReverse[str] (* "FDSRTYNHILHKNFUHG" *) And to check: MapAt[ Reverse, Transpose @ DeleteCases[Characters /@ {str, newStr} // Transpose, {a_, a_}], 1 ...

1

A simple solution that excludes self-replacement. Function[{s}, StringReplacePart[s, StringTake[s, ConstantArray[#[[1]], 2]], ConstantArray[#[[2]], 2]] &@ RandomSample[Range@StringLength@s, 2]]@"ORANGE" (note you could end up with the same string in the case of repeated characters in the input)

4

Experience shows that in order to understand a text it is by far not necessary that all ist letters to be correct. Here's a little game to experiment with it. We start with this text from Wikipedia: t = "Mathematica is a symbolic mathematical computation program, \ sometimes called a computer algebra program, used in many scientific, \ engineering, ...

4

Here's a slightly more involved approach that always changes a letter, or signals an error: ClearAll[MutateString]; MutateString::nomut = "All characters in string  are the same."; MutateString[s_String] := With[{choices = DeleteDuplicates[Characters[s]]}, With[{n = RandomInteger[{1, StringLength[s]}]}, StringReplacePart[s, ...

6

This will change the first occurrence of a random char by another random char f[s_] := StringReplace[s, Rule @@ RandomChoice[Characters@s, 2], 1] f@"ORANGE" (* "ORRNGE"*)

7

StringReplacePart[ # , RandomChoice[Characters@#] , {#, #} &@RandomInteger[{1, StringLength@#}] ] &@"ORANGE"

1

You can avoid pre-evaluation with the following definition ξ[n_Integer] := RandomVariate[NormalDistribution[]] RecurrenceTable[{y[n + 1] == y[n] ξ[n] + Sqrt[y[n]] ξ[n]^2, y[1] == 1}, {y}, {n, 1, 10}] (* {{1}, {1.39139}, {2.06846}, {0.0207897}, {0.0337668}, {0.18907}, \ {-0.193236}, {0.315955 + 0.300832 I}, {0.742221 + 0.264775 I}, {0.775734 + ...

12

the probability of a sequence of a given length being a word (as reported by DictionaryLookup): p[n_] := p[n] = (ToLowerCase /@ DictionaryLookup[StringExpression @@ ConstantArray[_, n]] // Union // Length)/26^n // N (* 27^n if spaces are to be included *) Show[{ ListLogPlot[Table[{n, p[n]}, {n, 3, 20}]], LogPlot[ 71625 ...

8

Of course the answer depends greatly on how you "randomly" choose the letters. Here is a Manipulate that reads in a source text, which is used to define the probability of occurrence of any given letter. It writes a short "poem" based on those probabilities. You can also look at probability "pairs" (how often a is followed by b, how often a is followed by c, ...

18

Just for comparing with Pillsy's answer, let's suppose we generate a uniformly random sequence of a-z and spacebar. SeedRandom[42]; n = 10^7; chars = Union[{" "}, CharacterRange["a", "z"]]; p = DictionaryLookup /@ StringSplit@ StringJoin@ RandomChoice[chars, n]; (Length@p - Count[p, {}])/ Length@p // N (* 0.0071783 *) 2558out of 356352 are "dictionary ...

13

Let's assume we're generating letters with the same frequency as they appear in the dictionary, in strings with lengths that have the same frequency as the lengths of words in the dictionary. To do this, first we need a list of words: In[1]:= words = DictionaryLookup[]; In[2]:= letters = (Values@# -> Keys@#) &@CharacterCounts[StringJoin[words]]; ...

8

Let's think about when the answer to this question may be relevant. You know that if using the same seed on two different occasions, the RNG will generate the same sequence of numbers. So the relevant questions are: Does Mathematica use the same seed after startup every time? No. This is easy to test. Many programs take the seed from the system time. ...

2

From documentation: You can use SeedRandom[n] to make sure you get the same sequence of pseudorandom numbers on different occasions. Reference SeedRandom

7

The problem consists of two questions: how to determine if circle is inside the ellipse and how to maximize the number of circles? 1. Circle is inside the ellipse? Let us show that the region of possible circle centers are bounded by a parallel curve of degree 8. ClearAll[x, y, a, b, r]; eq1 = Simplify[RegionDistance[Disk[{0, 0}, {a, b}], {x, y}]^2 == ...

2

An alternative count based on image processing. g2d2 = Graphics[{Disk[#, r] & /@ pts, Circle[{1/2, 1/2}, {2/5, 1/2}]}, PlotRange -> All, Frame -> False] img = g2d2 // Rasterize; c = MorphologicalComponents[ColorNegate@img]; sel = SelectComponents[ c, {"AdjacentBorderCount", "Area"}, #1 == 0 && 50 < #2 < 1000 ...

6

Solving this exactly is a hard or at least nontrivial problem if you want to prove the exact optimal number. Two things that are easier and still interesting in practice often are: Getting an upper bound for the number of circles in an ellipse From Circle Packing we know that $$\eta=\frac{\pi}{2\sqrt{3}}$$ is the highest possible density that can be ...

0

Using what you have already coded, first put them inside a module (You can shorten this part as suggested by LLlAMnYP). f[] := Module[{TA, L10, L9, L8, L7, L6, L5, L4, L3, L2, L1, TF1, TF2, TF3, TF4, TF5, TF6, TF7, TF8, TF9, TF10, m11, m12, m21, m22, t10a, T10a, R10a}, TA = {{1 - I*\[Beta]/(\[Omega]eg - \[Delta]), -I*\[Beta]/(\[Omega]eg - \ ...

2

As per my comment, this approach works: TA={{1-I*β/(ωeg-δ),-I*β/(ωeg-δ)},{I*β/(ωeg-δ),1+I*β/(ωeg-δ)}}; Do[L = Sort[RandomReal[10, 10]]; TF = {{Exp[4 π # I δ], 0}, {0, Exp[-4 π # I δ]}} & /@ ({First@L}~Join~Differences@L); m = Block[{TA}, Dot @@ Riffle[TF, TA, {2, 20, 2}]]; T[i] = With[{β = 0.16, ωeg = 1}, Evaluate@(Abs[m[[2, 2]]]^-2)];, {i, 1, ...

2

The required modification is not too hard to do: SeedRandom[159]; pts = Select[findPoints[npts, low, high, minD], EuclideanDistance[#, {1, 1} (low + high)/2] < (low + high)/2 - r &]; g2d = Graphics[{FaceForm @ Lighter[Blue, 0.8], EdgeForm @ Directive[Thickness[0.004], Black], Disk[#, r] & /@ pts, ...

3

Analytic approach: Manipulate[ SeedRandom["five"]; ListPointPlot3D[ RandomVariate[ TransformedDistribution[{a, b, c*a + (1 - c)*b}, {{a, b} \[Distributed] OrderDistribution[BinormalDistribution[r], {1, 2}]}], 10^3], PlotLabel -> Row[{"c = ", c, " | ", "r = ", r}]], {{c, 0.5}, 0, 1}, {{r, 0}, -.99, .99}]

0

Actually, given the code of J.M. it was easier than I thought. I post the complete workaround as an asnwer. Of course the credit goes to J.M. and that's why I accept his answer. BlockRandom[SeedRandom[143, Method -> "MersenneTwister"]; dom = {0, 10}; n = 20; lines = {RandomReal[dom, {2, 2}]}; k = 1; While[k < n, test = RandomReal[dom, {2, 2}]; ...

4

GraphicsMeshMeshInit[]; BlockRandom[SeedRandom[143, Method -> "MersenneTwister"]; dom = {10, 20}; n = 20; lines = {RandomReal[dom, {2, 2}]}; k = 1; While[k < n, test = RandomReal[dom, {2, 2}]; If[FindIntersections[{Line[lines], Line[test]}] === {}, k++; ...

11

RandomPartition[n_, p_] := Module[{r}, r = RandomSample[Range[n - 1], p - 1] // Sort; AppendTo[r, n]; Prepend[r // Differences, r[[1]]] ] RandomPartition[100, 16] (* {4, 1, 4, 3, 12, 5, 13, 3, 9, 8, 2, 2, 12, 11, 1, 10} *) RandomPartition[100, 16] // Total (* 100 *) Testing: And @@ Table[ n = RandomInteger[100000]; p = RandomInteger[{1, ...

3

Since v10.2 RandomPoint has provided a way to pick uniform samples from geometric regions (which you can trivially derive from your specification using ImplicitRegion): Eta[a_] := {Cos[a], Sin[a]}; NI[a_] := {Cos[a], Sin[a]}; reg = ImplicitRegion[ And @@ Table[ Dot[{x, y}, Eta[b]] <= Norm[NI[Pi] - Eta[b]]^2 + 2, {b, 0, 2 Pi, 2 Pi/10}], {x, ...

Top 50 recent answers are included