Scrappy Random

by Scrappy Ferret

About

Scrappy Random is a simple helper library for Solar2D that allows for working in a random fashion, such as generating random numbers, strings, colours, and UUIDs, as well as selecting from a list and flipping a coin. 

Using identical seeds it will generate the same results cross-platform.

API

A full API listing can be found here.

Examples

Create a random ‘user’.

-- Load plugin library
require "plugin.scrappyRandom"

-- Initiate and seed the generator
Scrappy.Random:init( os.time() )

-- Create some usernames
local usernames =
{
    "alice",
    "bob",
    "scrappyFerret",
    "glitchGames",
    "jason"
}

-- Choose a username from our names table
local username = Scrappy.Random:fromList( usernames )

-- Generate a 20 character long password that begins with a letter but doesn't include spaces
local password = Scrappy.Random:string( 20, { includeSpaces = false, beginWithALetter = true } )

-- Get a colour for the profile
local profileColour = Scrappy.Random:colour( true )

-- Decide their age
local age = Scrappy.Random:inRange( 1, 120 )

-- Flip a coin to see if they should have admin privileges. That's how everyone does it right?
local admin = Scrappy.Random:coinFlip()

-- Display the newly created user
print( "User Created - \nUsername: " .. username .. "\nPassword: " .. password .. "\nProfile Colour: " .. profileColour[ 1 ] .. ", " .. profileColour[ 2 ] .. ", " .. profileColour[ 3 ] .. "\nAge: " .. age .. "\nIs Admin?: " .. ( admin and "Yes" or "No" ) )

Trusted vendor

Documentation

$5.00

Log in now to purchase this plugin from Scrappy Ferret.

Once you've activated this plugin, appropriate build.settings code will be generated for you to copy into your Solar2D project. Download links will also be available for inclusion into a Solar2D Native project.

Latest Solar2D contributions by Scrappy Ferret view all