def randslice_from_slicelen(slicelen, listlen):
 maxstart = (listlen - slicelen)
 start = randrange((maxstart + 1))
 maxstep = (((listlen - start) // slicelen) if slicelen else 1)
 step = randrange(1, (maxstep + 1))
 stop = (start + (slicelen * step))
 s = slice(start, stop, step)
 (_, _, _, control) = slice_indices(s, listlen)
 if (control != slicelen):
  raise RuntimeError
 return s

def randslice_from_slicelen ( slicelen , listlen ) : maxstart = ( listlen - slicelen ) start = randrange ( ( maxstart + 1 ) ) maxstep = ( ( ( listlen - start ) // slicelen ) if slicelen else 1 ) step = randrange ( 1 , ( maxstep + 1 ) ) stop = ( start + ( slicelen * step ) ) s = slice ( start , stop , step ) ( _ , _ , _ , control ) = slice_indices ( s , listlen ) if ( control != slicelen ) : raise RuntimeError return s
create a random slice of len slicelen that fits into listlen .