Skip to content

Commit

Permalink
Merge pull request #3 from hannesm/add-stdlibrandom
Browse files Browse the repository at this point in the history
import mirage-stdlib-random
  • Loading branch information
yomimono committed Jan 17, 2017
2 parents 903b3ee + b1801d0 commit 503b771
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 5 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
@@ -0,0 +1,14 @@
language: c
install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh
script: bash -ex .travis-opam.sh
sudo: required
env:
global:
- PACKAGE="mirage-random"
- EXTRA_REMOTES="https://github.com/mirage/mirage-dev.git"
matrix:
- OCAML_VERSION=4.02
- OCAML_VERSION=4.03
- OCAML_VERSION=4.04
notifications:
email: false
6 changes: 4 additions & 2 deletions README.md
@@ -1,7 +1,9 @@
## mirage-random -- Random signatures for MirageOS
## mirage-random -- Random signatures for MirageOS, and an implementation using stdlib

mirage-random defines [Mirage_random.S][1] and [Mirage_random.C][2]
the signature for random-related devices for MirageOS.
the signature for random-related devices for MirageOS. It also
provides an implementation of `C` using `Random` from the OCaml standard
library.

[1]: https://mirage.github.io/mirage-random/Mirage_random.S.html
[2]: https://mirage.github.io/mirage-random/Mirage_random.C.html
Expand Down
3 changes: 2 additions & 1 deletion doc/api.odocl
@@ -1 +1,2 @@
Mirage_random
src/Mirage_random
std/Stdlibrandom
6 changes: 5 additions & 1 deletion pkg/META
@@ -1,3 +1,7 @@
description = "Random-related devices for MirageOS"
version = "%%VERSION_NUM%%"
requires = ""
requires = "cstruct"
archive(byte) = "stdlibrandom.cma"
archive(native) = "stdlibrandom.cmxa"
plugin(byte) = "stdlibrandom.cma"
plugin(native) = "stdlibrandom.cmxs"
4 changes: 3 additions & 1 deletion pkg/pkg.ml
Expand Up @@ -6,4 +6,6 @@ open Topkg
let () =
Pkg.describe "mirage-random" @@ fun c ->
Ok [ Pkg.lib "pkg/META";
Pkg.lib ~exts:Exts.interface "src/mirage_random" ]
Pkg.lib ~exts:Exts.interface "src/mirage_random" ;
Pkg.mllib "std/stdlibrandom.mllib"
]
14 changes: 14 additions & 0 deletions std/stdlibrandom.ml
@@ -0,0 +1,14 @@

type buffer = Cstruct.t

type g = unit

let generate ?g:_g n =
let b = Cstruct.create n in
for i = 0 to pred n do
Cstruct.set_uint8 b i (Random.int 256)
done ;
b

let initialize () =
Random.self_init ()
5 changes: 5 additions & 0 deletions std/stdlibrandom.mli
@@ -0,0 +1,5 @@

include Mirage_random.S
with type buffer = Cstruct.t

val initialize : unit -> unit
1 change: 1 addition & 0 deletions std/stdlibrandom.mllib
@@ -0,0 +1 @@
Stdlibrandom

0 comments on commit 503b771

Please sign in to comment.