Appearance
随机
¥Random
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).
Random.id
Summary:
Return a unique identifier, such as "Jjwjg6gouWLXhMGKW"
, that is
likely to be unique in the whole world.
Arguments:
Source codeName | Type | Description | Required |
---|---|---|---|
n | Number | Optional length of the identifier in characters (defaults to 17) | No |
js
import { Random } from "meteor/random";
Random.id(
42
);
Random.secret
Summary:
Return a random string of printable characters with 6 bits of
entropy per character. Use Random.secret
for security-critical secrets
that are intended for machine, rather than human, consumption.
Arguments:
Source codeName | Type | Description | Required |
---|---|---|---|
n | Number | Optional length of the secret string (defaults to 43 characters, or 256 bits of entropy) | No |
js
import { Random } from "meteor/random";
Random.secret(
42
);
Random.choice
Summary:
Return a random element of the given array or string.
Arguments:
Source codeName | Type | Description | Required |
---|---|---|---|
arrayOrString | Array or String | Array or string to choose from | Yes |
js
import { Random } from "meteor/random";
Random.choice(
[]
);
Random.hexString
Summary:
Return a random string of n
hexadecimal digits.
Arguments:
Source codeName | Type | Description | Required |
---|---|---|---|
n | Number | Length of the string | Yes |
js
import { Random } from "meteor/random";
Random.hexString(
42
);