File: secure_rng.R

package info (click to toggle)
r-cran-openssl 2.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,312 kB
  • sloc: ansic: 3,074; sh: 20; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 904 bytes parent folder | download | duplicates (2)
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))