Giter Club home page Giter Club logo

randomgenerator's Introduction

#Random Generator (F#\C#)#

This F# library (plus C# API) is capable of generating random strings of variable length. The library can be configured to return strings containing alpha ['A'..'Z'], numeric ['0'..'9'], and/or characters (~!@#$%^&*()_+-=).

It can also generate large numbers of strings asynchronously with high randomness (less than 0.0025% duplicates in 100,000 generated strings).

Tests (NUnit) are provided to show how to use the library as well as ensure basic requirements of the libraries.

##F# Library## Random Generator relies on the caller to provide the instance of characters to use to generate the string(s). It accomplishes this through a recursive discriminated union:

open RandomGenerator.Lib
let charList = CharSet(Chars ['A'..'Z'], Chars ['0'..'9'])

Once the characters are defined the call to generate is simple:

charList |> Generate 25

Here the 25 represents how many characters should be contained in your string: "H0FPT9J6Y9PGU7SJQA72XQTWQ"

Additionally, Random Generator is capable of generating multiple strings with low probability of repeating.

// Generate 100000 strings of 9 characters each
let genStrings = charList |> GenerateMultiple 100000 9

There's also a helper in the Dupe module that I use to determine if the Generator has created duplicate results:

// findDuplicates returns a list of the duplicate values
genStrings |> Dupe.findDuplicates

*Note: This was written back in F# 2.0 w/o the F# PowerPack, this could be replaced w/ LINQ or a simpler helper now.

##C# API## The C# API wrapper was written to abstract some of the complexity of dealing with F# discriminated unions. The call from C# looks like:

//open RandomGenerator.Interop;
var gen = new Generator();
let myString = gen.Single(25);

There are several defaults built into the API, but you can override them in the constructor if need be:

// Three bools can be passed in which tell the generator which type(s) of characters to use: alpha, numeric, symbol
// By default it assumes alpha and numeric (not symbol)
var gen = new Generator(true, true, false);
let myString = gen.Singe(25);

You can also generate multiple strings just as simply:

var gen = new Generator();
let myStrings = gen.Multiple(100000, 25);

randomgenerator's People

Contributors

johnbfair avatar

Watchers

 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.