Skip to content
This repository was archived by the owner on Nov 27, 2017. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

randstr

A simple function can be used to generate a random string with the specified length. And, the range of the characters is configurable.

Note: Math.random() is used to generate random numbers in this module. But, it does not provide cryptographically secure random numbers. Do not use them for anything related to security. You can use the crypto.randomBytes() in Node.js or window.crypto.getRandomValues() in browser.

Installation

To install randstr, use npm

$ npm install randstr

For browsers, use bower

$ bower install randstr

Usage

For node.js:

var randstr = require('randstr');

// By default, randstr will use `A-Za-z0-9` characters to generate
// a random string, and the length of the string is 32.
randstr();
// >> "xtYRPnR8rM0M6izYTNv8gJd07thPIyN9"


// You can set the default length and range of the characters.
randstr.len = 16;
randstr.chars = 'abcdefghijkmn';

randstr();
// >> "cfhaffchimiblalg"


// However, you can still specify the length and the range of the characters
// to override the default settings when the randstr is called.
randstr(6);
// >> "e3pTse"

randstr(6, '0123456789');
// >> "823748"

For browsers:

<script src="bower_components/randstr/randstr.js"></script>
<script>
randstr();
// >> "xtYRPnR8rM0M6izYTNv8gJd07thPIyN9"
</script>

LICENSE

Under the MIT license.

About

A simple function can be used to generate a random string with the specified length. And, the range of the characters is configurable.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages