EDIT
I have the following code which generates (pseudo-) randomly oriented and distributed but not intersecting lines. In fact, the code is from the reply I got here:
appendLine[list_Symbol] := (list = RandomReal[10, {1, 2, 2}])
appendLine[list_List] :=
Module[{newline, test = True},
For[newline = RandomReal[10, {2, 2}], test,
test = !
AllTrue[Solve[
RegionMember[Line[newline], {x, y}] &&
RegionMember[Line[#], {x, y}]] & /@ list, Length@# == 0 &],
newline = RandomReal[10, {2, 2}]];
Append[list, newline]]
SeedRandom[1247]
list =.
Do[list = appendLine[list], {n, 15}]
ln1 = (Line /@ list) /.
Line[a_] :> {Thick, If[RandomInteger[{1, 2}] == 1, Dashed],
Line[a]};
g1 = Graphics[ln1]
The original question had to do with SeedRandom
but it was too trivial and I found the workaround on my own. Then I modified my question to something less trivial. I apologize for any confusion this may have caused!
My question restated (I hope) with better wording is:
How is it possible to modify the appendLine
user-defined function in order to get exactly the same distribution of lines but in another "square" of side 10?
such as
EDIT 2
Thanks to the smart code of J.M. I am almost there. Unfortunately, I realized that it does not give me exactly what I want. The mistake is mine of course and not of J.M. who replied me to what I asked. I do not know if I have to ask a new thread. In order (I hope!) to be more specific let me create a real example.
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}];
If[FindIntersections[{Line[lines], Line[test]}] === {}, k++;
AppendTo[lines, test]]];
gLines1 =
Graphics[{RandomChoice[{Directive[Thick, Dashed], Thick}],
Line[#]} & /@ lines, Frame -> True, PlotRange -> {dom, dom}]];
BlockRandom[SeedRandom[143, Method -> "MersenneTwister"];
dom = {12.5, 22.5}; n = 20;
lines = {RandomReal[dom, {2, 2}]}; k = 1;
While[k < n, test = RandomReal[dom, {2, 2}];
If[FindIntersections[{Line[lines], Line[test]}] === {}, k++;
AppendTo[lines, test]]];
gLines2 =
Graphics[{RandomChoice[{Directive[Thick, Dashed], Thick}],
Line[#]} & /@ lines, Frame -> True, PlotRange -> {dom, dom}]];
BlockRandom[SeedRandom[143, Method -> "MersenneTwister"];
dom = {-12.5, -2.5}; n = 20;
lines = {RandomReal[dom, {2, 2}]}; k = 1;
While[k < n, test = RandomReal[dom, {2, 2}];
If[FindIntersections[{Line[lines], Line[test]}] === {}, k++;
AppendTo[lines, test]]];
gLines3 =
Graphics[{RandomChoice[{Directive[Thick, Dashed], Thick}],
Line[#]} & /@ lines, Frame -> True, PlotRange -> {dom, dom}]];
gRecA = Graphics[{FaceForm[GrayLevel[1]],
EdgeForm[Directive[Thick, Black]],
Rectangle[{-12.5, 0}, {-2.5, 10}]}];
gRecB = Graphics[{FaceForm[GrayLevel[0.7]],
EdgeForm[Directive[Thick, Black]],
Rectangle[{-12.5, -5}, {-2.5, -15}]}];
gRecC = Graphics[{FaceForm[GrayLevel[1]],
EdgeForm[Directive[Dotted, Black]], Rectangle[{0, 0}, {10, 10}]}];
gRecD = Graphics[{FaceForm[GrayLevel[0.7]],
EdgeForm[Directive[Thick, Black]],
Rectangle[{12.5, 0}, {22.5, 10}]}];
plusequal =
Graphics[{Line[{{-1.5, 5}, {-0.5, 5}}],
Line[{{-1.0, 5.6}, {-1.0, 4.4}}], Line[{{-1.5, 5}, {-0.5, 5}}],
Line[{{10.5, 5.2}, {11.5, 5.2}}],
Line[{{10.5, 4.8}, {11.5, 4.8}}]}];
Show[{gRecA, gRecB, gRecC, gRecD, gLines1, plusequal, gLines2,
gLines3}, PlotRange -> All, Frame -> True]
We see that we got the same distribution (as I originally wanted) of non-intersecting lines and in the same x-domain as that of the squares but there was also the unpleasant side-effect of y-translation. Once again the mistake was mine. I want the randomly distributed lines to fit inside these squares.
So, the whole idea is given a square of side 10 like Graphics[{FaceForm[GrayLevel[0.7]], EdgeForm[Directive[Thick, Black]],
Rectangle[{-12.5, -5}, {-2.5, -15}]}]
"fit" this distribution of lines inside it.
SeedRandom[1234]; list =. Do[list = appendLine[list], {n, 15}] // AbsoluteTiming ln1 = (Line /@ list) /. Line[a_] :> {Thick, If[RandomInteger[{1, 2}] == 1, Dashed], Line[a]}; g1 = Graphics[ln1]
. $\endgroup$If[RandomInteger[{1, 2}] == 1
toIf[RandomInteger[1] == 0
. A teeny bit faster. $\endgroup$