-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- URL we serve this under is docs/cookbook/[task slug]/[recipe slug] - multiple recipes per task - recipe page displays links to other recipes for the same task
- Loading branch information
Showing
14 changed files
with
330 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
cookbook_categories: | ||
- title: Command Line | ||
folder: command-line | ||
tasks: [] | ||
- title: Compression | ||
folder: compression | ||
tasks: [] | ||
- title: Concurrency | ||
folder: concurrency | ||
tasks: [] | ||
- title: Cryptography | ||
folder: cryptography | ||
tasks: [] | ||
- title: Database | ||
folder: database | ||
tasks: [] | ||
- title: Date and Time | ||
folder: date-and-time | ||
tasks: | ||
- title: Get Today's Date | ||
folder: get-today-date | ||
- title: Debugging | ||
folder: debugging | ||
tasks: [] | ||
- title: Encoding | ||
folder: encoding | ||
tasks: [] | ||
- title: File System | ||
folder: file-system | ||
tasks: [] | ||
- title: Garbage Collector | ||
folder: garbage-collector | ||
tasks: [] | ||
- title: Generate Random Values | ||
folder: generate-random-values | ||
tasks: | ||
- title: Generate random numbers | ||
folder: generate-random-numbers | ||
- title: Generate random strings and arrays | ||
folder: generate-random-strings-and-arrays | ||
- title: Hash Tables and Maps | ||
folder: hash-tables-and-maps | ||
tasks: [] | ||
- title: Mathematics | ||
folder: mathematics | ||
tasks: [] | ||
- title: Networking | ||
folder: networking | ||
tasks: [] | ||
- title: Operating System | ||
folder: operating-system | ||
tasks: [] | ||
- title: Sorting | ||
folder: sorting | ||
tasks: [] | ||
- title: Text Processing | ||
folder: text-processing | ||
tasks: [] | ||
- title: Web Programming | ||
folder: web-programming | ||
tasks: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
data/cookbook/generate-random-numbers/00-mirage-crypto-rng.md
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
...cookbook/generate-random-values/generate-random-numbers/00-mirage-crypto-rng.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
packages: | ||
- name: "mirage-crypto-rng" | ||
version: "0.11.2" | ||
- name: "randomconv" | ||
version: "0.1.3" | ||
sections: | ||
- filename: main.ml | ||
language: ocaml | ||
code_blocks: | ||
- explanation: | | ||
Initialize the RNG with the default entropy source. | ||
code: | | ||
let () = Mirage_crypto_rng_unix.initialize | ||
(module Mirage_crypto_rng.Fortuna) | ||
- explanation: | | ||
Generate a `Cstruct.t` with random data. | ||
code: | | ||
let cstruct n = Mirage_crypto_rng.generate n | ||
- explanation: | | ||
Use the `Randomconv` module from the `randomconv` package to convert to various integer types. | ||
code: | | ||
let int8 () = Randomconv.int8 cstruct | ||
let int16 () = Randomconv.int16 cstruct | ||
let int32 () = Randomconv.int32 cstruct | ||
let int64 () = Randomconv.int64 cstruct | ||
- explanation: | ||
Generate a random `int` or `float` less than or equal to `max`. | ||
code: | | ||
let int ?max () = | ||
Randomconv.int ?bound:max cstruct | ||
let float ?max () = | ||
Randomconv.float ?bound:max cstruct | ||
--- |
42 changes: 42 additions & 0 deletions
42
...nerate-random-values/generate-random-strings-and-arrays/00-mirage-crypto-rng.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
packages: | ||
- name: "mirage-crypto-rng" | ||
version: "0.11.2" | ||
- name: "randomconv" | ||
version: "0.1.3" | ||
sections: | ||
- filename: main.ml | ||
language: ocaml | ||
code_blocks: | ||
- explanation: | | ||
Initialize the RNG with the default entropy source. | ||
code: | | ||
let () = Mirage_crypto_rng_unix.initialize | ||
(module Mirage_crypto_rng.Fortuna) | ||
- explanation: | | ||
Generate a `Cstruct.t` with random data. | ||
code: | | ||
let cstruct n = Mirage_crypto_rng.generate n | ||
- explanation: | | ||
To get a random `char`, convert a random `int8`: | ||
code: | | ||
let char () = Char.chr (int8 ()) | ||
- explanation: | | ||
Use `Cstruct`'s conversion methods to obtain random byte arrays, bigarrays or strings. | ||
code: | | ||
let bytes n = cstruct n |> Cstruct.to_bytes | ||
let bigarray n = cstruct n |> Cstruct.to_bigarray | ||
let string n = cstruct n |> Cstruct.to_string | ||
- explanation: | | ||
You can also create alphanumeric random characters: | ||
code: | | ||
let alphanum () = | ||
Char.chr (48 + Randomconv.int ~bound:74 cstruct) | ||
- explanation: | | ||
Wrap your random value generator into a sequence to generate as many random values as you want. | ||
code: | | ||
let seq gen = | ||
Seq.unfold (fun () -> Some (gen (), ())) () | ||
let list n gen = | ||
seq gen |> Seq.take n |> List.of_seq | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.