OAuthProvider::generateToken

Generate a random token

&reftitle.description; final public static `string` `OAuthProvider::generateToken` `int` `size` `bool` `strong`&false;

Generates a `string` of pseudo-random bytes.

&reftitle.parameters;

`size`

- The desired token length, in terms of bytes.

`strong`

- Setting to &true; means `/dev/random` will be used for entropy, as otherwise the non-blocking `/dev/urandom` is used. This parameter is ignored on Windows.

&reftitle.returnvalues;

The generated token, as a `string` of bytes.

&reftitle.errors;

If the `strong` parameter is &true;, then an `E_WARNING` level error will be emitted when the fallback `rand` implementation is used to fill the remaining random bytes (e.g., when not enough random data was found, initially).

&reftitle.examples;

### `OAuthProvider::generateToken` example

    <?php
    $p = new OAuthProvider();

    $t = $p->generateToken(4);

    echo strlen($t),  PHP_EOL;
    echo bin2hex($t), PHP_EOL;

    ?>

&example.outputs.similar;

    4
    b6a82c27

&reftitle.notes;

When not enough random data is available to the system, this function will fill the remaining random bytes using the internal PHP `rand` implementation.

&reftitle.seealso;

- `openssl_random_pseudo_bytes`
- `mcrypt_create_iv`