# simple-random

> A simple flexible javascript library that creates random alpha-numeric strings. Works in both NodeJS and the browser.

Latest version **1.0.3** (published 2015-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-random
pnpm add simple-random
yarn add simple-random
bun add simple-random
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2015-05-23 |
| First published | 2014-12-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Dor Tzur |
| Maintainers | dortzur |
| Keywords | random, alpha-numeric, temporary, temp, tempfile, simple, secure, security, password |

## Links

- npm: https://www.npmjs.com/package/simple-random
- Repository: https://github.com/dortzur/simple-random
- Issues: https://github.com/dortzur/simple-random/issues
- npm.io page: https://npm.io/package/simple-random

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2015-05-23
- 1.0.2 — 2015-05-23
- 1.0.1 — 2015-05-23
- 1.0.0 — 2015-05-23
- 0.3.3 — 2014-12-15
- 0.3.2 — 2014-12-15
- 0.3.1 — 2014-12-15
- 0.2.4 — 2014-12-09
- 0.2.3 — 2014-12-09
- 0.2.2 — 2014-12-09
- 0.2.1 — 2014-12-05
- 0.1.1 — 2014-12-05

## README

# Simple Random
[![Build Status](https://travis-ci.org/dortzur/simple-random.svg?branch=master)](https://travis-ci.org/dortzur/simple-random)  [![npm version](https://badge.fury.io/js/simple-random.svg)](http://badge.fury.io/js/simple-random) [![npm](http://img.shields.io/npm/dm/simple-random.svg)](https://www.npmjs.com/package/simple-random)

A simple flexible javascript library that creates random alpha-numeric strings. Very useful when creating random names for files, folders. Can also create secure random strings for temporary passwords and salts.

Works in both NodeJS and the browser.

###Secure Random 
if the `secure` option is set to `true`, we can create a random byte seed with a cryptography library as opposed to Math.random().
In Node we use the default `crypto` library.
In webpack / browser versions we use the Web Cryptography API if supported.

##Installation
```bash
npm install simple-random --save 
```
##Usage
###Node
```javascript
var sr = require('simple-random');
var randomString = sr(); // Generates a 16 character alpha-numeric string.
// Example output: "pnxTcl2nOBqTNFQR"
```
###WebPack
```javascript
var sr=require('simple-random/browser'); 
var randomString = sr(); // Generates a 16 character alpha-numeric string.
// Example output: "pnxTcl2nOBqTNFQR"
```
###Browser
```html
<script src="simple-random/dist/simple_random.js"></script>
<script>
var randomString = window.simpleRandom();

//Secure Random
var secureRandom;
if (simpleRandom.isSecureSupported){
  secureRandom = simpleRandom({secure:true})
}

</script>
```



##Options
- `length`: The length of the alpha-numeric string (default 16).
- `digits`: should allow digits in random string (default true).
- `letters`: should allow letters in random string (default true).
- `caseSensitive`: if set to false, only lowercase letter characters will be used (default true).
- `secure`: Whether or not to use the `crypto` library for secure random byte seed as opposed to `Math.random()` (default false).
- `prefix`: Prefix.
- `suffix`: Suffix.
- `chars`: A string containing all the characters to draw from, defaults to all alpha-numeric characters (overrides digits, letters and caseSensitive flags).

---
_Source: https://npm.io/package/simple-random · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
