Code Monkey home page Code Monkey logo

randoml's Introduction

Randoml

A library to generate random numbers for cryptographic applications in OCaml. It relies on the rand Rust library.

Installation

You'll need Rust: https://rustup.rs/

Then:

$ opam install randoml

Or if you have esy:

{
    "dependencies": {
+        "@opam/randoml": "*"
    },
}

Usage

Fill a buffer with random bytes:

let buf = Bytes.create 16 in
rand_fill buf

Get a random int32:

let x = rand_int32 ()

Get a random int64:

let x = rand_int64 ()

Get a random int32 between 1 and 100000000:

let lower = Int32.of_int_exn 1 in
let upper = Int32.of_int_exn 100000000 in
let x = rand_int32_range lower upper

Get a random int64 between 1 and 100000000:

let lower = Int64.of_int_exn 1 in
let upper = Int64.of_int_exn 100000000 in
let x = rand_int64_range lower upper

Get a random Bigint upperbounded by some number (warning: it won't work well if your upperbound is not smaller and close to a power of 2):

let upperbound =
Bigint.of_string
    "7067388259113537318333190002971674063309935587502475832486424805170478604"
in
let x = rand_bigint upperbound

How to produce new releases of this library

As opam installs dependencies in a sandbox, rust dependencies need to be vendored via cargo vendor. Thus, this command needs to be executed every time there's a change in the Cargo.lock file.

randoml's People

Contributors

mimoo avatar mseri avatar et7f3 avatar gridbugs avatar

Stargazers

ran avatar Mukesh Tiwari avatar Seb Mondet avatar Evgeny avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

et7f3 gridbugs

randoml's Issues

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.