Hot answers tagged

11

Well, facinating question! Code first: Clear["`*"]; n = 5; steps = 1000; dir = {{0, 0}, {1, 0}, {0, 1}}; start = FromDigits[#, 2] & /@ Transpose@Append[RandomChoice[dir, n - 1], RandomInteger[1, 2]]; move[pt_] :=With[{c = RandomChoice@Pick[-dir, BitAnd @@ (# + pt) & /@ -dir, 0]}, pt + c +RandomChoice@DeleteCases[dir, -c]]; move[{2^n, 0}] := {2^n -...


6

Use AnglePath. SeedRandom["wolfram"]; ListLinePlot[AnglePath[RandomReal[{-Pi, Pi}, 100]], Axes -> None, Frame -> True]


6

randomWalk[t_] := Accumulate[ Prepend[RandomPoint[DiscretizeRegion[Circle[]], t], {0, 0}]]//ListLinePlot randomWalk[100] EDIT (3D Case) Borrowing @eldo's idea here: randomWalk[t_] := (Accumulate[Prepend[RandomPoint[DiscretizeRegion[Sphere[]], t], {0, 0, 0}]] // ListPointPlot3D) /. Point -> Line


6

Add this simple code before u run everything will let Random generate exactly the same result every time you run. If you're careful enough, you may find this in lot's of posts with randomly generated input. SeedRandom["Whatever you write here, keep it the same in multiple runs!"] Hope this can help you!


5

As noted by previous answerers, the desired distributional properties of the spherical random walk was not properly clarified. Nevertheless, let me offer two variations of interest. The first variation is the spherical analog of the bounded random walk (this recent thread shows a few ways on how to implement this). This would seem to have been the variation ...


4

RandomPoint makes this a one liner (as of version 10.2): RandomPoint[Sphere[{0, 0, 0}, 4]] {1.80874, 3.43311, -0.970669} Or get multiple points at once: RandomPoint[Sphere[{0, 0, 0}, 4], 10] {{-2.15717, -0.871558, -3.25377}, {1.65153, 2.06714, -2.99989}, {-0.798, 3.91915, -0.0591287}, {-2.19946, 3.2677, 0.696074}, {3.21113, 2.00556, 1.29087}, {...


3

As a general solution, you can always Export you data to a file. L = 10; random = Table[{x, y, RandomReal[{-1, 1}]}, {x, 0, L, L/10}, {y, 0, L, L/10}]; Export[NotebookDirectory[]<>"rand.dat",Flatten[random,1]] Next time you want to use this data random = Import[NotebookDirectory[]<>"rand.dat"]; One benefit of using data file is you can use ...


3

You can save your trained classifier in .mx file and simply load it in the new session. data = {{1, "a"} -> True, {2, "b"} -> True, {3, "b"} -> True, {4, "a"} -> True, {5, "a"} -> False, {6, "b"} -> True}; c = Classify[data, Method -> "RandomForest"]; c[{5, "b"}, "Probabilities"] <|False -> 0.202281, True -> 0.797719|> ...


3

Here is an approach that generates many more points than you had, selects the ones for which your conditions are met, and plots them: k1[s_, d_] := 3 s + 5 d k2[s_, d_] := 5 s - 7 d ps = RandomVariate[UniformDistribution[{{0.1, 2}, {-1, 3}}], 1000000]; valid = Select[ps, 0 < k1[Sequence @@ #] <= 1 && 0 < k2[Sequence @@ #] <= 2 &]; ...


3

Your approach is a dead end, you can't determine all points by picking them and checking conditions. Because there are infinitely many of them. ImplicitRegion[ 0 < k1[x, y] <= 1 && 0 < k2[x, y] <= 2, {x, y} ] // RegionPlot


3

Try the following code: pt=Accumulate[{Sin@#,Cos@#}&/@RandomReal[{0,2 Pi},1000]]; boundary={Min@pt,Max@pt}; (*Distance is here*) Norm@Last@pt ListLinePlot[pt,PlotRange->{boundary,boundary},AspectRatio->1] The result will be: Also,I suspect you may need to run it multiple times and track it's end points distribution, so try this: pt = Table[...


2

randomWalk[steps_] := With[ {pts = FoldList[Plus, {0, 0}, Normalize /@ RandomReal[{0, 1}, {steps, 2}]]}, Graphics[{Line[pts], Red, Point[pts]}] ] randomWalk[5]


1

This appears to be a bug. Histogram shows result of 100K RV on PascalDistribution[1,1/50] for 100k batch using RandomVariate[...,100000] (blue) and generating a table of 100k single calls (default chicken-poop-and-mud jaundice beige): Thanks to Karsten for verification and Jim for histogram idea.


1

In the t1 case Random`DistributionVector[PascalDistribution[1, 1/50], 10000, ∞] is evaluated and in the t2 case Random`DistributionVector[PascalDistribution[1, 1/50], 10, ∞] The definition of this function contains a Which statement. Its first test is True for 10000 and False for 10. Its second test (there are only two) is True. For your parameters ...


1

Just an extended comment: Rather than a consistent shift for the values in the minimum values for t2, it appears that the distribution is completely different than for t1, t3, and t4. Here's a figure showing that: h[x_, label_] := Histogram[Min /@ x, {1}, "PDF", PlotRange -> {{0, 30}, {0, 0.20}}, PlotLabel -> Style[label, Bold, Larger]] ...



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