Code Monkey home page Code Monkey logo

caprice's Introduction

About

A Go client for RANDOM.org. Generate truly random numbers in your code!

Example

package main

import (
	"github.com/AkshatM/caprice"
	"fmt"
)

func main() {
	rng := caprice.TrueRNG(<api key>)

	// generate 10 integers in base 10 between 1 and 100 with no duplicates 
	intArray, err := rng.GenerateIntegers(10, 1, 100, false)
	fmt.Printf("%v, intArray)

	// same as last time, but get back the entirety of the JSON response as a Result struct
	result, err := rng.GenerateIntegersRaw(10, 1, 100, false)
	fmt.Printf("%+v", result)

	// same as last time, but get back a structure that contains all the information you need
	// to verify the data you received along with the data itself in convenient format.
	verifiableResult, err := rng.GenerateSignedIntegers(10, 1, 100, false)
	fmt.Printf("%v", verifiableResult.Data) // actual data
	fmt.Printf("%+v", verifiableResult)
}

Installation

For now,

go get -u github.com/AkshatM/caprice

Documentation

Working on getting this into Godoc. For now, consult the source.

With the exception of verifySignature, all API calls are supported as listed here and here.

  • Per Go convention, all API calls begin with capitalised letters.
  • Every basic API call x has a corresponding method called xRaw that will return a Response object. e.g. GenerateIntegers has GenerateIntegersRaw. This is useful if you need access to any of the other response items RANDOM.org returns. Signed methods already return the raw JSONified data as well as the actual data supplied, so no equivalent exists for signed methods.
  • verifySignature currently has issues :( however, you can still verify the integrity of your data by taking the signature and raw fields of the result struct from a signed method manually.

Road Map

1.0:

  • Add support for using advisoryDelay, making this code truly thread-safe.
  • Get documentation up.
  • Add mocked network calls for decoupled testing.

caprice's People

Contributors

akshatm 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.