randomly sort a result set according to the data adapter class
358905
def random_sort(set)
      set.order do
        # this is a bit of a hack obviously, but it checks the sort of
        # data engine being used to figure out how to randomly sort
        if set.class.name !~ /mysql/i
          random.function
        else
          rand.function
        end
      end
    end
1062332
@Override
	public List<V> load(final int first, final int pageSize,
			final List<SortMeta> multiSortMeta,
			final Map<String, Object> filters) {

		final boolean filtersChanged = handleFilters(filters);
		final boolean sortOrderChanged = handleSortOrder(multiSortMeta);
		boolean notify = false;

		// clear cache
		if (filtersChanged || sortOrderChanged) {
			adaptee.clearCache();
			notify = filtersChanged || notifyOnSortOrderChanges;
		}

		adaptee.setPageSize(pageSize);
		final int size = adaptee.getSize();
		adaptee.setFirst(first >= size ? Math.max(0, size - 1) : first);
		setRowCount(size);

		// notify observers
		if (filtersChanged && clearSelectionOnFilterChanges) {
			adaptee.clearSelection();
		}
		if (notify) {
			adaptee.notify(ChangeEventType.DATA);
		}

		return adaptee.getData();
	}
556655
def select(self, **kws):
        '''
            
        '''
        lst = [i for i in self.values() if i.select(**kws)]

        random.shuffle(lst)

        return lst
921531
def nsorted(to_sort, key=None):
    """"""
    if key is None:
        key_callback = _natural_keys
    else:
        def key_callback(item):
            return _natural_keys(key(item))

    return sorted(to_sort, key=key_callback)
690017
def _argsort_and_resolve_ties(time, random_state):
        """"""
        n_samples = len(time)
        order = numpy.argsort(time, kind="mergesort")

        i = 0
        while i < n_samples - 1:
            inext = i + 1
            while inext < n_samples and time[order[i]] == time[order[inext]]:
                inext += 1

            if i + 1 != inext:
                # resolve ties randomly
                random_state.shuffle(order[i:inext])
            i = inext
        return order
213400
public <T extends Comparable<? super T>> List<T> sort (Collection<T> data)
    {
        return sort(new ArrayList<T>(data));
    }
1059559
@Override
    public DataBinder process(ResultSet rset) throws Exception {
        try {
            if (rset.next()) {
                ResultSetMetaData meta = rset.getMetaData();
                int width = meta.getColumnCount();
                for (int i = 1; i <= width; ++i) {
                    Object value = rset.getObject(i);
                    if (value != null) {
                        put(Strings.toLowerCamelCase(meta.getColumnLabel(i), '_'), value.toString());
                    }
                }
            } else {
                throw new NoSuchElementException("NoSuchRow");
            }
            return this;
        } finally {
            rset.close();
        }
    }
504382
def _shuffle_data(self):
        """"""
        # shuffle index
        np.random.shuffle(self.idx)
        # get the data by corresponding index
        self.data = _getdata_by_idx(self.data, self.idx)
        self.label = _getdata_by_idx(self.label, self.idx)
1011605
protected static <A> double[] ranks(final NumberArrayAdapter<?, A> adapter, final A data, int[] idx) {
    final int len = idx.length;
    double[] ret = new double[len];
    for(int i = 0; i < len;) {
      final int start = i++;
      final double val = adapter.getDouble(data, idx[start]);
      // Include ties:
      while(i < len && adapter.getDouble(data, idx[i]) <= val) {
        i++;
      }
      final double score = (start + i - 1) * .5 + 1;
      for(int j = start; j < i; j++) {
        ret[idx[j]] = score;
      }
    }
    return ret;
  }
612107
def _prepare_results(self, results):
        
        # if we want a result sorted by a score, and if we have a full result
        # (no slice), we can do it know, by creating keys for each values with
        # the sorted set score, and sort on them
        if self._sort_by_sortedset_after and (len(results) > 1 or self._values):
            conn = self.cls.get_connection()

            sort_params = {}
            base_tmp_key, tmp_keys = self._prepare_sort_by_score(results, sort_params)

            # compose the set to sort
            final_set = '%s_final_set' % base_tmp_key
            conn.sadd(final_set, *results)

            # apply the sort
            results = conn.sort(final_set, **sort_params)

            # finally delete all temporary keys
            conn.delete(*(tmp_keys + [final_set, base_tmp_key]))

        if self._store:
            # if store, redis doesn't return result, so don't return anything here
            return

        if self._values and self._values['mode'] != 'flat':
            results = self._to_values(results)

        return super(ExtendedCollectionManager, self)._prepare_results(results)
1261899
def shuffle_sattolo(items):
    """"""
    _randrange = random.randrange
    for i in reversed(range(1, len(items))):
        j = _randrange(i)  # 0 <= j < i
        items[j], items[i] = items[i], items[j]
1282060
def get_paginator(
        self,
        dataset,
        per_page,
        orphans=0,
        allow_empty_first_page=True,
        **kwargs
    ):
        """"""
        return IndefinitePaginator(
            dataset,
            per_page,
            orphans=orphans,
            allow_empty_first_page=allow_empty_first_page,
            **kwargs
        )
274680
private void orderResults(ResultSet cqlRows) throws InvalidRequestException
    {
        if (cqlRows.size() == 0 || !needsPostQueryOrdering())
            return;

        assert orderingIndexes != null;

        List<Integer> idToSort = new ArrayList<Integer>();
        List<Comparator<ByteBuffer>> sorters = new ArrayList<Comparator<ByteBuffer>>();

        for (ColumnIdentifier.Raw identifier : parameters.orderings.keySet())
        {
            ColumnDefinition orderingColumn = cfm.getColumnDefinition(identifier.prepare(cfm));
            idToSort.add(orderingIndexes.get(orderingColumn.name));
            sorters.add(orderingColumn.type);
        }

        Comparator<List<ByteBuffer>> comparator = idToSort.size() == 1
                                                ? new SingleColumnComparator(idToSort.get(0), sorters.get(0))
                                                : new CompositeComparator(sorters, idToSort);
        Collections.sort(cqlRows.rows, comparator);
    }
954332
public static <ItemType> BootstrapIterator<ItemType> forData(Iterable<? extends ItemType> data,
      Random rng) {
    return new BootstrapIterator<ItemType>(data, rng);
  }
514697
private static <V> Collection<V> sorted(Iterable<V> source, Comparator<V> comparator, int size)
    {
        V[] vs = (V[]) new Object[size];
        int i = 0;
        for (V v : source)
            vs[i++] = v;
        Arrays.sort(vs, comparator);
        return Arrays.asList(vs);
    }
293577
function(item) {
          var list = _listing.slice(0);
          return $q.when(list
            .filter(function(entity) {
              return entity.item !== item;
            })
            .sort(function() {
              return Math.random() > 0.5;
            })
            .splice(0,6));
        }
207704
def randomize_es(es_queryset):
    """"""
    return es_queryset.query(
        query.FunctionScore(
            functions=[function.RandomScore()]
        )
    ).sort("-_score")