The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/packages/random
Tasso Evangelista bc88ffa9a8
chore(deps): Upgrade TypeScript (#34064)
1 year ago
..
src refactor(tests): Align Jest tests (#32550) 1 year ago
.eslintrc.json refactor: Fork minor Meteor packages (#28337) 3 years ago
.gitignore refactor: Fork minor Meteor packages (#28337) 3 years ago
CHANGELOG.md Release 6.6.0 2 years ago
README.md refactor: Fork minor Meteor packages (#28337) 3 years ago
babel.config.js refactor: Fork minor Meteor packages (#28337) 3 years ago
jest.config.ts refactor(tests): Align Jest tests (#32550) 1 year ago
package.json chore(deps): Upgrade TypeScript (#34064) 1 year ago
tsconfig.build.json refactor(livechat): `@rocket.chat/random` instead of `crypto-js` (#30014) 2 years ago
tsconfig.json refactor: Fork minor Meteor packages (#28337) 3 years ago

README.md

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.