UNPKG

@codedipper/random-code

Version:

Generates a random code.

12 lines (9 loc) 289 B
export default function(n, ch){ var c = ""; if (n == "0" || n == null || !n) n = 10; if (!ch) ch = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"; for (var i = 0; i < parseInt(n); i++){ c += ch.split("")[Math.floor(Math.random() * ch.length)]; } return c; };