Skip to content

Commit b2d9641

Browse files
committed
Switch random(List) -> shuffle(List) in packages
Or sometimes randomSubset
1 parent 7087172 commit b2d9641

25 files changed

Lines changed: 56 additions & 64 deletions

M2/Macaulay2/packages/CodingTheory.m2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ C := linearCode G;
17901790
for i from 1 to 1 do(
17911791
message := transpose matrix {(for n from 1 to numgens target G list(random(R)))};
17921792
codeword := (transpose G)*message;
1793-
errors := sum take(random entries basis target codeword, 3);
1793+
errors := sum take(shuffle entries basis target codeword, 3);
17941794
errors = transpose matrix({errors});
17951795
received := codeword+errors;
17961796
decoded := syndromeDecode(C, received, 8);

M2/Macaulay2/packages/CpMackeyFunctors/Tests/BoxProductTests.m2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ assert (class (inverse f) ===MackeyFunctorHomomorphism)
2727

2828
-- Test induced map on box products
2929
for i to 5 do (
30-
p = (random {2,3,5,7})#0;
31-
n = (random toList (0..20))#0;
30+
p = random {2,3,5,7};
31+
n = random 21;
3232
M = makeRandomCpMackeyFunctor(p);
3333
A = makeBurnsideMackeyFunctor(p);
3434
timesn = map(A,A,n);

M2/Macaulay2/packages/Cremona.m2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ genericRestriction = (phi) -> (
16281628
K:=coefficientRing Pn;
16291629
x:=local x;
16301630
H:=K[x_0..x_(n-1)];
1631-
j:=map(H,Pn,random(toList(x_0..x_(n-1))|{random1 H}));
1631+
j:=map(H,Pn,shuffle(toList(x_0..x_(n-1))|{random1 H}));
16321632
j=map(H/j(ideal target phi),target phi,toMatrix j);
16331633
phi':=j*phi;
16341634
phi'

M2/Macaulay2/packages/EdgeIdeals.m2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ randomUniformHyperGraph (PolynomialRing,ZZ,ZZ) := (R,card,num) -> (
10381038
if card <= 0 then error "cardinalities of hypergraphs must be positive integers";
10391039
if num < 0 then error "number of edges must be nonnegative";
10401040
if num > binomial(numgens R,card) then error "can't make that many edges";
1041-
edges := take(random subsets(gens R,card),num);
1041+
edges := take(shuffle subsets(gens R,card),num);
10421042
hyperGraph(R,edges)
10431043
)
10441044

@@ -1049,7 +1049,7 @@ randomUniformHyperGraph (PolynomialRing,ZZ,ZZ) := (R,card,num) -> (
10491049
-----------------------------------------------------------
10501050
recursiveRandomHyperGraph = (V,L,D,BranchLimit,TerminateTime) -> (
10511051
if #D === 0 then return L;
1052-
V = random V;
1052+
V = shuffle V;
10531053
W := set take(V, D#0);
10541054
if any(L, l -> all(W, w-> member(w#0,l))) then return null;
10551055
if any(L, l -> all(l, w-> member(w#0,W))) then return null;

M2/Macaulay2/packages/FastMinors.m2

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ chooseRandomNonzeroSubmatrix(ZZ, Matrix) := opts -> (n1, M1) -> (
345345
--curList = flatten entries curM1;
346346
entryList = entries transpose matrix nonzeroEntries(curM1);
347347
if #entryList == 0 then return null;
348-
curEntry = entryList#(random(#entryList));
348+
curEntry = random entryList;
349349
--print (curList#curMax);
350350
curRow = curEntry#0;
351351
curCol = curEntry#1;
@@ -535,7 +535,7 @@ chooseMinorSmallestDegree(ZZ, MutableMatrix) := o -> (n1, M1) -> (
535535
randomMaxPosition = method(Options=>{});
536536
randomMaxPosition(List) := o -> (L1) -> (
537537
newList := apply(#L1, i -> {L1#i, random((#L1)^2), i});
538-
newList2 := random(newList);
538+
newList2 := shuffle(newList);
539539
j := maxPosition(newList2);
540540
return ((newList2#j)#2);
541541
);
@@ -544,7 +544,7 @@ randomMaxPosition(List) := o -> (L1) -> (
544544
randomMinPosition = method(Options=>{});
545545
randomMinPosition(List) := o -> (L1) -> (
546546
newList := apply(#L1, i -> {L1#i, random((#L1)^2), i});
547-
newList2 := random(newList);
547+
newList2 := shuffle(newList);
548548
j := minPosition(newList2);
549549
return ((newList2#j)#2);
550550
);
@@ -553,7 +553,7 @@ randomMinPosition(List) := o -> (L1) -> (
553553
randomMinPositions = method(Options=>{});
554554
randomMinPositions(ZZ, List) := o -> (n1, L1) -> (
555555
newList := apply(#L1, i -> {L1#i, random((#L1)^2), i});
556-
newList2 := random(newList);
556+
newList2 := shuffle(newList);
557557
newList3 := sort(newList2);
558558
return apply(take(n1, newList3), z -> z#0);
559559
);
@@ -622,10 +622,8 @@ chooseRandomSubmatrix = method(Options=>{});
622622

623623
chooseRandomSubmatrix(ZZ, Matrix) := opts -> (n1, M1) ->
624624
(
625-
rowL := random(toList(0..(numRows M1 - 1)));
626-
colL := random(toList(0..(numColumns M1 - 1)));
627-
rowL = sort take(rowL, n1);
628-
colL = take(colL, n1);
625+
rowL := randomSubset(numRows M1, n1);
626+
colL := take(shuffle toList(0..<numColumns M1), n1);
629627
return {rowL, colL};
630628
)
631629

@@ -648,7 +646,7 @@ reorderPolynomialRing(Symbol, Ring) := opts-> (myOrder, R1) -> (
648646
if (debugLevel > 0) then print "reorderPolynomialRing: it is a polynomialRing";
649647
coeff := coefficientRing R1;
650648
genList := generators R1;
651-
newGenList := random(genList);
649+
newGenList := shuffle(genList);
652650
return coeff[newGenList, MonomialOrder => myOrder];)
653651
else (return R1);
654652
);

M2/Macaulay2/packages/GKMVarieties/Tests_GKMVarieties.m2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Tests for GKMVarieties.m2
88
-- flagGeomTuttePolynomial test
99
--------------------------------
1010
TEST ///
11-
ML = (random drop(drop(allMatroids 4,1),-1))_{0,1}
11+
ML = (shuffle drop(drop(allMatroids 4,1),-1))_{0,1}
1212
TML = apply(ML, m -> {tuttePolynomial m, flagGeomTuttePolynomial flagMatroid({m})}) -- 2.5 seconds
1313
assert all(TML, l -> (map(ring first l, ring last l, gens ring first l))(last l) == first l)
1414
N = flagMatroid(matrix{{1,1,1},{1,0,0}},{1,2})

M2/Macaulay2/packages/IntegralClosure.m2

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,17 +466,14 @@ randomMinors(ZZ,ZZ,Matrix) := (n,d,M) -> (
466466
then return (minors(d,M))_*;
467467
L := {}; -- L will be a list of minors, specified by the pair of lists "rows" and "cols"
468468
dets := {}; -- the list of determinants taken so far
469-
rowlist := toList(0..r-1);
470-
collist := toList(0..c-1);
471-
ds := toList(0..d-1);
472469

473470
for i from 1 to n do (
474471
-- choose a random set of rows and of columns, add it to L
475472
-- only if it doesn't appear already. When a pair is added to L,
476473
-- the corresponding minor is added to "dets"
477474
while (
478-
rows := sort (random rowlist)_ds ;
479-
cols := sort (random collist)_ds ;
475+
rows := randomSubset(r, d);
476+
cols := randomSubset(c, d);
480477
for p in L do (if (rows,cols) == p then break true);
481478
false)
482479
do();
@@ -493,13 +490,10 @@ nonzeroMinor(ZZ,Matrix) := opts -> (d,M) -> (
493490
c := numcols M;
494491
if d > min(r,c) then return null;
495492
candidate := 0_(ring M);
496-
rowlist := toList(0..r-1);
497-
collist := toList(0..c-1);
498-
ds := toList(0..d-1);
499493
for i from 1 to opts.Limit do(
500494
-- choose a random set of rows and of columns, test the determinant.
501-
rows := sort (random rowlist)_ds ;
502-
cols := sort (random collist)_ds ;
495+
rows := randomSubset(r, d);
496+
cols := randomSubset(c, d);
503497
candidate = det (M^rows_cols);
504498
if candidate != 0 then return(candidate);
505499
);

M2/Macaulay2/packages/Macaulay2Doc/ov_threads.m2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Node
4141
including cpu caches; it is like running Macaulay2 on a computer that is running other big
4242
programs at the same time. We can see this using @ TO "elapsedTime" @.
4343
Example
44-
L = random toList (1..10000);
44+
L = shuffle toList (1..10000);
4545
elapsedTime apply(1..100, n -> sort L);
4646
elapsedTime parallelApply(1..100, n -> sort L);
4747
Text

M2/Macaulay2/packages/Matroids.m2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ relabel (Matroid, List) := Matroid => (M, perm) -> (
747747
)
748748
relabel Matroid := Matroid => M -> (
749749
E := toList(0..<#M_*);
750-
relabel(M, (transpose{E, random E})/toSequence//hashTable)
750+
relabel(M, (transpose{E, shuffle E})/toSequence//hashTable)
751751
)
752752
753753
-- Recursively finds all permutations inducing a bijection on circuits (note: permutations(10) is already slow on a typical machine)

M2/Macaulay2/packages/MultiprojectiveVarieties.m2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ line (EmbeddedProjectiveVariety,EmbeddedProjectiveVariety) := (X,p) -> (
10001000
if dim V >= 2 then return linearSpan {p,point V};
10011001
L := select(decompose V,l -> dim l == 1 and degree l == 1);
10021002
if # L == 0 then error("failed to find line in "|toString(? X));
1003-
first random L
1003+
random L
10041004
);
10051005
line (EmbeddedProjectiveVariety,ZZ) := (X,n) -> (
10061006
L := try line(X,point X) else null;

0 commit comments

Comments
 (0)