def randslice(qs, limit, exclude=None):
 cnt = qs.count()
 if (exclude is not None):
  limit += 1
 rand = (0 if (limit > cnt) else random.randint(0, (cnt - limit)))
 slice_ = list(qs[rand:(rand + limit)])
 if (exclude is not None):
  slice_ = [o for o in slice_ if (o.pk != exclude)][:(limit - 1)]
 return slice_

def randslice ( qs , limit , exclude = None ) : cnt = qs . count ( ) if ( exclude is not None ) : limit += 1 rand = ( 0 if ( limit > cnt ) else random . randint ( 0 , ( cnt - limit ) ) ) slice_ = list ( qs [ rand : ( rand + limit ) ] ) if ( exclude is not None ) : slice_ = [ o for o in slice_ if ( o . pk != exclude ) ] [ : ( limit - 1 ) ] return slice_
get a random slice of items from qs of size limit .