random
Documentation of Meteor's random
package.
The random
package provides several functions for generating randomnumbers. It uses a cryptographically strong pseudorandom number generator whenpossible, but falls back to a weaker random number generator whencryptographically strong randomness is not available (on older browsers or onservers that don’t have enough entropy to seed the cryptographically stronggenerator).
Anywhere
Random.id
import { Random } from 'meteor/random' (random/random.js, line 191)
Return a unique identifier, such as "Jjwjg6gouWLXhMGKW"
, that islikely to be unique in the whole world.
Arguments
- nNumber
- Optional length of the identifier in characters (defaults to 17)
Anywhere
Random.secret
import { Random } from 'meteor/random' (random/random.js, line 209)
Return a random string of printable characters with 6 bits ofentropy per character. Use Random.secret
for security-critical secretsthat are intended for machine, rather than human, consumption.
Arguments
- nNumber
- Optional length of the secret string (defaults to 43 characters, or 256 bits of entropy)
Anywhere
Random.fraction
import { Random } from 'meteor/random' (random/random.js, line 132)
Return a number between 0 and 1, like Math.random
.
Anywhere
Random.choice
import { Random } from 'meteor/random' (random/random.js, line 227)
Return a random element of the given array or string.
Arguments
- arrayOrStringArray or String
- Array or string to choose from
Anywhere
Random.hexString
import { Random } from 'meteor/random' (random/random.js, line 153)
Return a random string of n
hexadecimal digits.
Arguments
- nNumber
- Length of the string