Skip to content

Commit

Permalink
Create randomLam.m2
Browse files Browse the repository at this point in the history
function which inputs integers (n,k) and returns a random partition of size k with length at most n
  • Loading branch information
juanlanfranco authored Jun 2, 2024
1 parent ec10638 commit ab0d03d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions randomLam.m2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
randomLam = method();
randomLam(ZZ, ZZ) := (n,k) -> (
L=new MutableList from {};
sumsofar = 0;
for i from 0 to (n-2) do(
x = random(0, k-sumsofar);
L#i=x;
sumsofar = sumsofar + x;
);
L#(n-1) = k - sumsofar;
L=toList L;
L=rsort L;
return delete(0,L)
)

0 comments on commit ab0d03d

Please sign in to comment.