[Crypto] Add secure rand-nth fn
This commit is contained in:
parent
f6c17a7411
commit
e16c64c4f4
1 changed files with 4 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
(ns taoensso.nippy.crypto
|
(ns taoensso.nippy.crypto
|
||||||
"Low-level crypto utils.
|
"Low-level crypto utils.
|
||||||
Private & alpha, very likely to change!"
|
Private & alpha, very likely to change!"
|
||||||
|
(:refer-clojure :exclude [rand-nth])
|
||||||
(:require [taoensso.encore :as enc]))
|
(:require [taoensso.encore :as enc]))
|
||||||
|
|
||||||
;; Note that AES128 may be preferable to AES256 due to known attack
|
;; Note that AES128 may be preferable to AES256 due to known attack
|
||||||
|
|
@ -28,7 +29,9 @@
|
||||||
(defn rand-double "Uses `prng`" ^double [] (.nextDouble (prng)))
|
(defn rand-double "Uses `prng`" ^double [] (.nextDouble (prng)))
|
||||||
(defn rand-long "Uses `prng`" ^long [] (.nextLong (prng)))
|
(defn rand-long "Uses `prng`" ^long [] (.nextLong (prng)))
|
||||||
(defn rand-gauss "Uses `prng`" ^double [] (.nextGaussian (prng)))
|
(defn rand-gauss "Uses `prng`" ^double [] (.nextGaussian (prng)))
|
||||||
(defn rand-bool "Uses `prng`" [] (.nextBoolean (prng))))
|
(defn rand-bool "Uses `prng`" [] (.nextBoolean (prng)))
|
||||||
|
(defn rand-nth "Uses `prng`"
|
||||||
|
[coll] (nth coll (int (* (rand-double) (count coll))))))
|
||||||
|
|
||||||
(comment (seq (rand-bytes 16)))
|
(comment (seq (rand-bytes 16)))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue