Applies the given <code>randSeq</code> to rearrange the given collection in a random order.
If <code>randSeq</code> is <code>null</code>, returns the collection in normal order.
433695
public static <T> List<T> order( RandSeq randSeq, Collection<T> collection)
    {
    return reorderIf( randSeq, new ArrayList<T>( collection));
    }
459839
public static <T> T randomElementOf(final List<T> list) {
        if (list.isEmpty()) {
            return null;
        }
        return list.get(nextInt(0, list.size()));
    }
1242508
def randdeque(self):
        
        return deque(
            self.randint
            for x in range(0, self.random.randint(3, 10)))
404345
public static <E extends Comparable<E>> void recursiveQuickSort(List<E> array, int startIdx,
      int endIdx) {

    int idx = partition(array, startIdx, endIdx);

    // Recursively call quicksort with left part of the partitioned array
    if (startIdx < idx - 1) {
      recursiveQuickSort(array, startIdx, idx - 1);
    }

    // Recursively call quick sort with right part of the partitioned array
    if (endIdx > idx) {
      recursiveQuickSort(array, idx, endIdx);
    }
  }
231430
public static <E> ImmutableList<E> shuffledCopy(List<? extends E> list, Random rng) {
    final ArrayList<E> shuffled = Lists.newArrayList(list);
    Collections.shuffle(shuffled, rng);
    return ImmutableList.copyOf(shuffled);
  }
35479
def rand(self, count=1):
        
        result = self._client.srandmember(self.key_prefix, count)
        return set(map(self._loads, result))
1056883
public static ObjectSequence<TimeSeriesCollection> fixSequence(ObjectSequence<TimeSeriesCollection> seq) {
        seq = seq.sort();  // Does nothing if already sorted.

        if (!seq.isDistinct() && !seq.isEmpty()) {
            List<ObjectSequence<TimeSeriesCollection>> toConcat = new ArrayList<>();
            int lastGoodIdx = 0;
            int curIdx = 0;

            while (curIdx < seq.size()) {
                final TimeSeriesCollection curElem = seq.get(curIdx);

                // Find first item with different timestamp.
                int nextIdx = curIdx + 1;
                while (nextIdx < seq.size()
                        && curElem.getTimestamp().equals(seq.get(nextIdx).getTimestamp())) {
                    ++nextIdx;
                }

                // If more than 1 adjecent element share timestamp, merge them together.
                if (curIdx + 1 < nextIdx) {
                    toConcat.add(seq.limit(curIdx).skip(lastGoodIdx));

                    TimeSeriesCollection replacement = new LazyMergedTSC(seq.limit(nextIdx).skip(curIdx));
                    toConcat.add(ObjectSequence.of(true, true, true, replacement));
                    lastGoodIdx = curIdx = nextIdx;
                } else {
                    // Advance curIdx.
                    ++curIdx;
                }
            }

            if (lastGoodIdx < curIdx)
                toConcat.add(seq.skip(lastGoodIdx));
            seq = ObjectSequence.concat(toConcat, true, true);
        }

        return seq;
    }
496242
public static <T> List<T> randomEles(List<T> list, int count) {
		final List<T> result = new ArrayList<T>(count);
		int limit = list.size();
		while (result.size() < count) {
			result.add(randomEle(list, limit));
		}

		return result;
	}
148395
public static void shuffle( byte []array , int offset , int length , Random rand ) {
		for (int i = 0; i < length; i++) {
			int src = rand.nextInt(length-i);
			byte tmp = array[offset+src+i];
			array[offset+src+i]=array[offset+i];
			array[offset+i] = tmp;
		}
	}
545786
public static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement) {
        TransposeDataCollection sampledIds = new TransposeDataCollection();
    
        for(Map.Entry<Object, FlatDataList> entry : strataIdList.entrySet()) {
            Object strata = entry.getKey();
            
            Number sampleN =  ((Number)nh.get(strata));
            if(sampleN==null) {
                continue;
            }
            
            sampledIds.put(strata, SimpleRandomSampling.randomSampling(entry.getValue(), sampleN.intValue(), withReplacement));
        }
        
        return sampledIds;
    }
1372022
public static <T> T randomEle(List<T> list, int limit) {
		return list.get(randomInt(limit));
	}
1356436
@Override
  public Iterator<T> iterator() {
    final List<T> shuffledList = Lists.newArrayList(data);
    Collections.shuffle(shuffledList, rng);
    return Collections.unmodifiableList(shuffledList).iterator();
  }
961461
public static <T> void sort(List<T> list, Comparator<? super T> comparator) {
		if (list instanceof RandomAccess) {
			quicksort(list, comparator);
		} else {
			List<T> copy = new ArrayList<>(list);
			quicksort(copy, comparator);
			list.clear();
			list.addAll(copy);
		}
	}
1216017
public <T> List<T> reorder( List<T> sequence)
    {
    int elementCount = sequence.size();
    if( elementCount > 1)
      {
      List<T> elements = new ArrayList<T>( sequence);
      sequence.clear();

      for( ; elementCount > 0; elementCount--)
        {
        sequence.add( elements.remove( generator_.nextInt( elementCount)));
        }
      }

    return sequence;
    }
1128275
public static <E> Collection<E> sampleWithoutReplacement(Collection<E> c, int n, Random r) {
    if (n < 0)
      throw new IllegalArgumentException("n < 0: " + n);
    if (n > c.size())
      throw new IllegalArgumentException("n > size of collection: " + n + ", " + c.size());
    List<E> copy = new ArrayList<E>(c.size());
    copy.addAll(c);
    Collection<E> result = new ArrayList<E>(n);
    for (int k = 0; k < n; k++) {
      double d = r.nextDouble();
      int x = (int) (d * copy.size());
      result.add(copy.remove(x));
    }
    return result;
  }
1304263
@SuppressWarnings("unchecked")
  // This is not good code, but what's there to be done? TODO
  public static <T> T sample(Counter<T> c, Random rand) {
    Iterable<T> objects;
    Set<T> keySet = c.keySet();
    objects = c.keySet();
    if (rand == null) {
      rand = new Random();
    } else { // TODO: Seems like there should be a way to directly check if T is
             // comparable
      if (!keySet.isEmpty() && keySet.iterator().next() instanceof Comparable) {
        List l = new ArrayList<T>(keySet);
        Collections.sort(l);
        objects = l;
      } else {
        throw new RuntimeException("Results won't be stable since Counters keys are comparable.");
      }
    }
    double r = rand.nextDouble() * c.totalCount();
    double total = 0.0;

    for (T t : objects) { // arbitrary ordering
      total += c.getCount(t);
      if (total >= r)
        return t;
    }
    // only chance of reaching here is if c isn't properly normalized, or if
    // double math makes total<1.0
    return c.keySet().iterator().next();
  }
367795
public static <T> List<T> randomSample(Collection<T> collection, int n) {
		List<T> list = new ArrayList<T>(collection);
		List<T> sample = new ArrayList<T>(n);
		Random random = new Random();
		while(n > 0  &&  !list.isEmpty()) {
			int index = random.nextInt(list.size());
			sample.add(list.get(index));
			int indexLast = list.size() - 1;
			T last = list.remove(indexLast);
			if(index < indexLast) {
				list.set(index, last);
			}
			n--;
		}
		return sample;
	}