Coder Social home page Coder Social logo

randy's Introduction

Randy

A little library for easily producing random data using Ruby's built-in rand function.

Installation

Add this line to your application's Gemfile:

gem 'randy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install randy

Usage

Currently randy can produce two kinds of random data (in theory this will change).

Strings

The original main purpose of this library is to produce random strings easily.

For example, to produce a random 10-character string:

# Example output: BASWCEV3TQ
Randy.string(10)

By default, the result string will comprise characters from the digits 0-9 and the English alphabet.

This can be changed by specifying the characters to be used:

# Example output: baaabbabac
Randy.string(10, "abc")

Numbers

It's already easy to produce random numbers using Ruby. However, randy makes it even easier.

To produce a random integer, just specify a range:

# Will include some number between 1 and 10
Randy.integer(1..10)

The result will be consistent with how Ruby ranges work; that is, an inclusive range (..) will potentially include the upper bound while an exclusive range (...) will not.

Admittedly, the above is quite trivial to implement by hand, e.g., with 1 + rand(10). Think of it simply as a nicer interface to rand.

The same functionality is also exposed to decimal values:

Randy.decimal((1.4)..(6.2))

randy's People

Contributors

dtao avatar

Stargazers

 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.