A module that can return various types of random string
npm install random-string-alphanumeric-generator --save
var random = require('random-string-alphanumeric-generator');
random.randomAlphanumeric(10, "lowercase")
//Returns b2pdk4bv98
random.randomLetters(10, "uppercase")
//Returns ABHUISLCHF
- randomAlphanumeric
Generates a random string of given length
lettersIncluded optional field which can be one of following
all (default): Includes uppercase letters lowercase letters and numbers
lowercase: Includes lowercase letters and numbers
uppercase: Includes uppercase letters and numbers
random.randomAlphanumeric(10, lowercase) // uhf2m363l1
random.randomAlphanumeric(10, uppercase) // DG8CXMZ21F
random.randomAlphanumeric(10) // 5hiry73uV8
- randomLetters
Generates a random string of given length
lettersIncluded optional field which can be one of following
all (default): Includes uppercase letters lowercase letters and numbers
lowercase: Includes lowercase letters and numbers
uppercase: Includes uppercase letters and numbers
random.randomAlphanumeric(10, lowercase) // aqswedfrtg
random.randomAlphanumeric(10, uppercase) // KINHBGFYRS
random.randomAlphanumeric(10) // 5hiry73uV8 // KqjfrQNkth
- randomNumber
Generates a random number of given length
random.randomNumber(10) // 4369739553
- randomHex
Generates a random hex of given length Includes only hex characters i.e [0-9 and a-f]
random.randomHex(10) // 1dd12084e3
- randomBinary
Generates a random binary string of given length Includes only binary characters i.e [0 and 1]
random.randomBinary(10) // 1110011111
- randomOctal
Generates a random octal string of given length Includes only octal characters i.e [0-7]
random.randomOctal(10) // 2350150766
- customRandomString
Generates a random string of given length Includes only characters given in customCharSet
random.customRandomString(10, abcdef) // eadefcaffb
- getRandomPassword
Generates a random string of given length Includes numbers, small letters, capital letters and special characters Second optional param as minimum number of special characters required
random.getRandomPassword(10) // JkCtzL*!Pd
random.getRandomPassword(10, 2) // $)FN3A#dP^
- getRandomPasswordStrict
Generates a random string of given length Includes numbers, small letters, capital letters and special characters second optional param as fixed number of special characters required
random.getRandomPasswordStrict(10, 3) // #TUjLFgdRg
- getRndFloat
Generates random float between min(included) and max(excluded) numbers. Min: Default is 0 Max: Default is 1 Third optional param as number of digits after the decimal point default is 4
random.getRndFloat(4, 5, 3) // 4.304
- getRndInteger
Returns random integer between min(included) and max(excluded) numbers. Min: Default is 0 Max: Default is 100
random.getRndInteger(5, 50) // 7
- getRndBoolean
Generates random boolean true or false.
random.getRndBoolean() // True or False