https://github.com/haskell/entropy
Easy entropy source for Haskell users.
https://github.com/haskell/entropy
Last synced: about 1 month ago
JSON representation
Easy entropy source for Haskell users.
- Host: GitHub
- URL: https://github.com/haskell/entropy
- Owner: haskell
- License: other
- Created: 2013-05-12T19:21:56.000Z (over 12 years ago)
- Default Branch: main
- Last Pushed: 2025-01-02T12:52:04.000Z (about 1 year ago)
- Last Synced: 2025-10-25T05:21:17.473Z (3 months ago)
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/entropy
- Size: 109 KB
- Stars: 28
- Watchers: 5
- Forks: 50
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Introduction
This package allows Haskell users to easily acquire entropy for use in critical
security applications by calling out to either windows crypto api, unix/linux's
`getrandom` and `/dev/urandom`. Hardware RNGs (currently RDRAND, patches
welcome) are supported via the `hardwareRNG` function.
## Quick Start
To simply get random bytes use `getEntropy`:
```
#!/usr/bin/env cabal
{- cabal:
build-depends: base, entropy, bytestring
-}
import qualified Data.ByteString as BS
import System.Entropy
main :: IO ()
main = print . BS.unpack =<< getEntropy 16
-- Example output: [241,191,215,193,225,27,121,244,16,155,252,41,131,38,6,100]
```
## Faster Randoms from Hardware
Most x86 systems include a hardware random number generator. These can be
faster but require more trust in the platform:
```
import qualified Data.ByteString as B
import System.Entropy
eitherRNG :: Int -> IO B.ByteString
eitherRNG sz = maybe (getEntropy sz) pure =<< getHardwareEntropy sz
main :: IO ()
main = print . B.unpack =<< eitherRNG 32
```
This package supports Windows, {li,u}nix, QNX, and has preliminary support for HaLVM.
Typically tested on Linux and OSX - testers are as welcome as patches.
[](https://travis-ci.org/TomMD/entropy)