# weighted-random-file

> Pick a weighted random file from an array of files, based on the files' length.

Latest version **0.2.0** (published 2017-02-23) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install weighted-random-file
pnpm add weighted-random-file
yarn add weighted-random-file
bun add weighted-random-file
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2017-02-23 |
| First published | 2017-02-02 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Just Thomas Hiorth Misund |
| Maintainers | misund |

## Links

- npm: https://www.npmjs.com/package/weighted-random-file
- Repository: https://github.com/misund/weighted-random-file
- Homepage: https://github.com/misund/weighted-random-file#readme
- Issues: https://github.com/misund/weighted-random-file/issues
- npm.io page: https://npm.io/package/weighted-random-file

## Dependencies (2)

- [trailing-slash-it](https://npm.io/package/trailing-slash-it.md) 0.3.0
- [weighted-random-object](https://npm.io/package/weighted-random-object.md) 1.0.6

## Recent versions

- 0.2.0 (latest) — 2017-02-23
- 0.1.1 — 2017-02-16
- 0.0.1 — 2017-02-02

## README

`weighted-random-file` pick a weighted random file, based on it's length.

 The longer the file is, the more often it will be chosen. A 4 kB file will be
 returned twice as often as a 2 kB file.

 Returns a Promise, so it's thenable.

## Install
```
$ npm install --save weighted-random-file
```

## Usage
```js
var weightedRandomFile = require("weighted-random-file");

weightedRandomFile(['one.txt', 'two.txt', 'three.txt'], __dirname); // "two.txt"
weightedRandomFile(['one.txt', 'two.txt', 'three.txt'], '/path/to/files'); // "two.txt"
```

## Parameters
* an array of relative paths
* base directory (optional, default is the location of `weighted-random-file`)

## Returns
A Promise of a string containing a relative path.

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