<template name="pkg_random">
{{#better_markdown}}
## `random`

The `random` package provides several functions for generating random
numbers. It uses a Meteor-provided random number generator that does not depend
on the browser's facilities.

<dl class="callbacks">
{{#dtdd "Random.id()"}}
Returns a unique identifier, such as `"Jjwjg6gouWLXhMGKW"`, that is likely to
be unique in the whole world.
{{/dtdd}}

{{#dtdd "Random.fraction()"}}
Returns a number between 0 and 1, like `Math.random`.
{{/dtdd}}

{{#dtdd "Random.choice(arrayOrString)"}}
Returns a random element of the given array or string.
{{/dtdd}}

{{#dtdd "Random.hexString(n)"}}
Returns a random string of `n` hexadecimal digits.
{{/dtdd}}
</dl>

{{#note}}
In the current implementation, random values do not come from a
cryptographically strong pseudorandom number generator. Future releases will
improve this, particularly on the server.
{{/note}}
{{/better_markdown}}
</template>

<template name="pkg_random">
{{#better_markdown}}
## `random`

The `random` package provides several functions for generating random
numbers. It uses a cryptographically strong pseudorandom number generator when
possible, but falls back to a weaker random number generator when
cryptographically strong randomness is not available (on older browsers or on
servers that don't have enough entropy to seed the cryptographically strong
generator).

<dl class="callbacks">
{{#dtdd "Random.id()"}}
Returns a unique identifier, such as `"Jjwjg6gouWLXhMGKW"`, that is likely to
be unique in the whole world.
{{/dtdd}}

{{#dtdd "Random.fraction()"}}
Returns a number between 0 and 1, like `Math.random`.
{{/dtdd}}

{{#dtdd "Random.choice(arrayOrString)"}}
Returns a random element of the given array or string.
{{/dtdd}}

{{#dtdd "Random.hexString(n)"}}
Returns a random string of `n` hexadecimal digits.
{{/dtdd}}
</dl>

{{/better_markdown}}
</template>

Use cryptographic PRNGs when available.
Use cryptographic PRNGs when available.

This means node's crypto.randomBytes on the server, and
window.crypto.getRandomValues on the client. If node's crypto.randomBytes throws
an exception, we fall back to crypto.pseudoRandomBytes. If
window.crypto.getRandomValues isn't supported by the browser, we fall back to
the alea generator that we had been using previously.
