def random_integer_partition(n, seed=None):
 from sympy.utilities.randtest import _randint
 n = as_int(n)
 if (n < 1):
  raise ValueError('n must be a positive integer')
 randint = _randint(seed)
 partition = []
 while (n > 0):
  k = randint(1, n)
  mult = randint(1, (n // k))
  partition.append((k, mult))
  n -= (k * mult)
 partition.sort(reverse=True)
 partition = flatten([([k] * m) for (k, m) in partition])
 return partition

def random_integer_partition ( n , seed = None ) : from sympy . utilities . randtest import _randint n = as_int ( n ) if ( n < 1 ) : raise ValueError ( 'n must be a positive integer' ) randint = _randint ( seed ) partition = [ ] while ( n > 0 ) : k = randint ( 1 , n ) mult = randint ( 1 , ( n // k ) ) partition . append ( ( k , mult ) ) n -= ( k * mult ) partition . sort ( reverse = True ) partition = flatten ( [ ( [ k ] * m ) for ( k , m ) in partition ] ) return partition
generates a random integer partition summing to n as a list of reverse-sorted integers .