Rocket.Chat/packages/random
2025-12-20 13:19:36 -03:00
..
src chore: Enforce stricter TypeScript directives (#37709) 2025-12-08 10:25:25 -03:00
.eslintrc.json chore(random): Review build configuration (#37901) 2025-12-20 13:19:36 -03:00
.gitignore
CHANGELOG.md Release 6.6.0 2024-02-07 01:22:58 +00:00
jest.config.ts refactor(tests): Align Jest tests (#32550) 2024-08-11 19:38:29 -04:00
package.json chore(random): Review build configuration (#37901) 2025-12-20 13:19:36 -03:00
README.md
tsconfig.build.json chore(random): Review build configuration (#37901) 2025-12-20 13:19:36 -03:00
tsconfig.json chore(random): Review build configuration (#37901) 2025-12-20 13:19:36 -03:00

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([n]) - Returns a unique identifier, such as "Jjwjg6gouWLXhMGKW", that is likely to be unique in the whole world. The optional argument n specifies the length of the identifier in characters and defaults to 17.

  • Random.secret([n]) - Returns a random string of printable characters with 6 bits of entropy per character. The optional argument n specifies the length of the secret string and defaults to 43 characters, or 256 bits of entropy. Use Random.secret for security-critical secrets that are intended for machine, rather than human, consumption.

  • Random.fraction() - Returns a number between 0 and 1, like Math.random.

  • Random.choice(arrayOrString) - Returns a random element of the given array or string.

  • Random.hexString(n) - Returns a random string of n hexadecimal digits.