Either a reference to a container whose lifetime is not shorter than that of the subset or permutation object, or a "bare" container type for a temporary object. See also the detailed discussion.
Either a functor class satisfying the extended requirements for unary operations, or an untyped template of such a class wrapped into BuildUnary or BuildUnaryIt (preferably expressed via the convenience typedef from namespace polymake::operations.
This is a convenience function, which allows to embed a temporary object into an expression without writing down its exact type. The result is identical to a direct call to the constructor of the corresponding class with the same arguments.
Please note that this and similar convenience functions always create an object parameterized with references to the input data (containers.) Sometimes, especially in a function return statement, you will need a reference-less variant; then you have to use the constructor.
Either a functor class satisfying the extended requirements for binary operations, or an untyped template of such a class wrapped into BuildBinary or BuildBinaryIt (preferably expressed via the convenience typedef from namespace polymake::operations.
The template parameter inherits the const attribute from the corresponding function argument. A pseudo-container with a const reference to the source data is in its turn immutable.

### Prerequisits

    #include <random_generators.h>
    using namespace polymake;

### Uniform distribution

The most popular (and primitive) sources of random numbers available on a standard UNIX system are put together with GMP random number generators under the unified wrapper interface:

template <typename ElementType> class UniformRNG;

Partially implements the STL Container interface. The lacking methods are size(), max_size(), and empty(), as they do not make much sense on an apparently unlimited data stream.

Two iterators over the same UniformRNG object will supply different data elements, since the state information is kept by the latter and is being changed by each data request (that is, iterator::operator* ) However, an UniformRNG object copied from another one will produce the same data sequence, since it inherits the whole internal state information from the original object, and the generating algorithms are deterministic.

Besides the iterator interface, you can also call the generator's method get() directly. The results will be the same.

Currently, the class UniformRNG is defined for the following data types. While the data access methods are identical (as prescribed by the Container interface,) the constructors sometimes look differently.

UniformRNG< long > (); UniformRNG< long > (unsigned long seed);
Generates integral numbers from the range [0, 231). Uses nrand48, the stateless variant of the well-known lrand48 function.
UniformRNG< double > (); UniformRNG< double > (unsigned long seed);
Generates floating-point numbers from the range [0,1). Uses erand48, the stateless variant of the well-known drand48 function.
UniformRNG< Integer > (unsigned long bitlength=48); UniformRNG< Integer > (unsigned long bitlength, unsigned long seed); UniformRNG< Integer > (unsigned long bitlength, const Integer& seed);
Generates integral numbers from the range [0, 2bitlength). Uses the GMP function mpz_urandomb.
UniformRNG< Rational > (unsigned long bitlength=48); UniformRNG< Rational > (unsigned long bitlength, unsigned long seed); UniformRNG< Rational > (unsigned long bitlength, const Integer& seed);
Generates rational numbers from the range [0,1). Really only the numerators are random, belonging to [0, 2bitlength); the denominators are always some powers of 2.
UniformRNG< Bitset > (int max_elem); UniformRNG< Bitset > (int max_elem, unsigned long seed); UniformRNG< Bitset > (int max_elem, const Integer& seed);
Generates sets of integers belonging to the range [0, max_elem). Effectively, it works just the same as UniformRNG< Integer >, but masquerades the produced values as sets.

### Normal distribution

class NormalRNG; NormalRNG (); NormalRNG (unsigned long seed);

Generates floating-point numbers normally distributed in (-1,1). The algorithm is taken from Donald E. Knuth, The Art of Computer Programming, vol. II, 3.2.1, Alg. P. The number source is UniformRNG< double > .

### Integers with given distribution

class DiscreteRNG; template <typename Container> DiscreteRNG (const Container& distribution); template <typename Container&> DiscreteRNG (const Container& distribution, unsigned long seed);

Generates a sequence of integers from the range 0 .. distribution.size()-1 . The values of distribution are interpreted as relative probabilities of the corresponding numbers to appear. They can be arbitrary positive numbers, not necessarily summing up to 1, as the probabilities are normalized in the constructor.

## Random selection

### Prerequisits

    #include <RandomSubset.h>
    using namespace polymake;

There are two alias pseudo-container classes randomly choosing elements from a given container. Both implement the STL Container interface. Repetitive data access operations will yield different selections!

template <typename ContainerRef> class RandomSubset; RandomSubset< Container& > select_random_subset(Container& c, int k); RandomSubset< Container& > select_random_subset(Container& c, int k, unsigned long seed);
Choose k elements randomly. Each possible k-subset has equal probability to appear. The chosen elements preserve their order in the original container c.
template <typename ContainerRef=sequence> class RandomPermutation; RandomPermutation< Container& > random_permutation (Container& c); RandomPermutation< Container& > random_permutation (Container& c, unsigned long seed);
Visit the elements in a random order. Each possible permutation has equal probability to appear. Container must be of bidirectional or random-access category.
RandomPermutation<> random_permutation(int n); RandomPermutation<> random_permutation(int n, unsigned long seed);
Create a random permutation of the integer sequence [0..n).

## Random seed values

All constructors and convenience functions introduced on this page come in two flavors: one taking an explicit seed value and another with default seed. The latter is taken from the system entropy source `/dev/random`, which is usually available on the most modern UNIX platforms. If not, the seed value is constructed from the current time (measured with microsecond precision), process id, and the internal call counter. This allows to avoid repeating identical pseudo-random sequences even if the random generator object is born in a quickly iterating loop.

You can also obtain these "random seed" values from the following function:

unsigned long random_seed ();