Giter Site home page Giter Site logo

rand's Introduction

rand

A collection of utility functions for generating random strings and numbers in various formats. This library provides easy-to-use functions to create random values for different use cases, including Base10, Base36, Base62 strings, UUIDv4, and random numbers within specified ranges or of specified lengths.

Installation

npm install @se-oss/rand

API

// Generates a random string of a specified length using the provided characters.
declare function random(chars: string, length: number): string;

// Generates a random string of a specified length using Base62 characters (A-Z, a-z, 0-9).
declare function randomBase62(length: number): string;

// Generates a random string of a specified length using Base36 characters (a-z, 0-9).
declare function randomBase36(length: number): string;

// Generates a random string of a specified length using Base10 characters (0-9).
declare function randomBase10(length: number): string;

// Generates a random UUIDv4 string.
declare function randomUuidv4(): string;

// Generates a random number within a specified range or of a specified length.
declare function randomNumber(min: number, max: number): number;
declare function randomNumber(length: number): number;

Examples

Here are some examples of how to use the Random class:

import {
  randomBase62,
  randomBase36,
  randomBase10,
  randomUuidv4,
  randomNumber
} from '@se-oss/random';

// Generate a random Base62 string of length 12
console.log(randomBase62(12)); // Example output: 'A1b2C3d4E5f6'

// Generate a random Base36 string of length 8
console.log(randomBase36(8)); // Example output: '1a2b3c4d'

// Generate a random Base10 string of length 4
console.log(randomBase10(4)); // Example output: '5678'

// Generate a random UUIDv4 string
console.log(randomUuidv4()); // Example output: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'

// Generate a random number between 1 and 10
console.log(randomNumber(1, 10)); // Example output: 5

// Generate a random number of length 16
console.log(randomNumber(16)); // Example output: 8933580352864351

Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.

Thanks again for your support, it is much appreciated!

License

MIT © Shahrad Elahi

rand's People

Contributors

shahradelahi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.