File: secure_rng.R

package info (click to toggle)
r-cran-openssl 1.2.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,136 kB
  • sloc: ansic: 2,033; sh: 19; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 869 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## ---- echo = FALSE, message = FALSE--------------------------------------
knitr::opts_chunk$set(comment = "")
library(openssl)

## ------------------------------------------------------------------------
rnd <- rand_bytes(10)
print(rnd)

## ------------------------------------------------------------------------
as.numeric(rnd)

## ------------------------------------------------------------------------
x <- rand_bytes(1)
as.logical(rawToBits(x))

## ------------------------------------------------------------------------
rand_num(10)

## ------------------------------------------------------------------------
# Secure rnorm
x <- qnorm(rand_num(1000), mean = 100, sd = 15)
hist(x)

## ------------------------------------------------------------------------
# Secure rbinom
y <- qbinom(rand_num(1000), size = 20, prob = 0.1)
hist(y, breaks = -.5:(max(y)+1))