# randomlib

# Types

# Functions

`pub fn byte_iterator(rnd: Random) -> Iterator(Int)`

Returns an iterated that generates byte in Int form when iterated Note that the random seed is internally updated but there is no ability to extract the updated seed

```
pub fn choice(
rnd: Random,
choices: List(a),
) -> Result(Iterator(a), Nil)
```

If non-empty choices list is provided, returns an iterator that performs a uniformly distributed selection from the the items in the list If no choices are passed an Error(Nil) is returned

`pub fn float_iterator(rnd: Random) -> Iterator(Float)`

Returns an iterated that generates uniformly distributed Floats when iterated Note that the random seed is internally updated but there is no ability to extract the updated seed

`pub fn new() -> Random`

Creates a new random seed with distinctness set using the current time, nominally in nanoseconds. Please note that the actual timings will be microseconds for erland and milliseconds for javascript, so any new random seeds generated in that same time scale will be the same

`pub fn next(rnd: Random, bits: Int) -> #(BigInt, Random)`

Returns a tuple containing a BigInt of size n bits and the updated random seed Note that this hasn’t been fully tested to generate uniformly distributed values

`pub fn next_bool(rnd: Random) -> #(Bool, Random)`

Returns a tuple containing a uniformly distributed Bool and the updated random seed

`pub fn next_byte(rnd: Random) -> #(Int, Random)`

Returns a tuple containing a byte (0-255) in Int form and the updated random seed

`pub fn next_bytes(rnd: Random, n: Int) -> #(List(Int), Random)`

Returns a tuple containing a list of n bytes in Int form and the updated random seed Passing n <= 0 will return an empty list

`pub fn next_float(rnd: Random) -> #(Float, Random)`

Returns a tuple containing a uniformly distributed float between 0.0 (inclusive) and 1.0 (exclusive) and the updated random seed

```
pub fn next_int(
rnd: Random,
limit: Int,
) -> Result(#(Int, Random), Random)
```

Returns a result containing either a tuple containing a uniformly distributed Int (where int is 31 bits unsigned) and the updated random seed or an error containing the random seed (currently not updated)