Algorithmic Solutions > LEDA > LEDA Guide > Simple, Basic, and Advanced Data Types > Simple Data Types > Random Sources

## Random Sources

The data type random_source is a random number generator (based on the function random() from Berkeley UNIX). It can be used to generate uniformly distributed random bits, characters, ints and doubles.

It can be in either of two modes:

• In bit mode: it generates a random bit string of some length p ( 1 < = p < = 31)
• In integer mode: it generates a random integer in some range [low..high] ( low < = high < low + 231).

Remark: The data type random_source is only pseudorandom. The seed depends on the internal clock.

### Example

The following program generates a random integer between 0 and 231 and outputs it.
```#include <LEDA/core/random_source.h>

int main()
{
leda::random_source S;
int ri;
S >> ri;
std::cout << ri << std::endl;

return 0;
}```

### Tip

Extract characters and boolean values only from sources whose range spans powers of two, otherwise the distribution is not uniform.