# Passenger::RandomGenerator Class Reference

A random data generator. More...

`#include <RandomGenerator.h>`

List of all members.

## Public Member Functions
string | generateAsciiString (unsigned int size)
| Generates a random string of size bytes which is also valid ASCII.

## Detailed Description

A random data generator.

Data is generated using /dev/urandom, and is cryptographically secure. Unlike rand() and friends, RandomGenerator does not require seeding.

The reason why RandomGenerator isn't a singleton is because opening /dev/urandom is *very* slow on Mac OS X and OpenBSD. Each object of this class caches the /dev/urandom file handle.

This class is thread-safe as long as there are no concurrent calls to reopen() or close().

## Member Function Documentation

string Passenger::RandomGenerator::generateAsciiString | ( | unsigned int | size | ) | `[inline]`

Generates a random string of size bytes which is also valid ASCII.

The result consists only of the characters A-Z, a-z and 0-9, and therefore the total number of possibilities given a size of N is 62**N. However not every character has an equal chance of being chosen: a-i have 5/256 chance of being chosen, while other characters have 4/256 chance of being chosen. Therefore, to match the entropy of a random binary string of size N, one should choose a size which yields slightly more possibilities than 2**N.

The documentation for this class was generated from the following file:

- RandomGenerator.h