-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to generate random numbers using a secure source provided by the system. It actually uses the same source as SecureRandom.
- Loading branch information
1 parent
53dc365
commit e1330f1
Showing
6 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "spec" | ||
require "random/system" | ||
|
||
describe "Random::System" do | ||
rng = Random::System.new | ||
|
||
it "returns random numbers from the secure system source" do | ||
typeof(rng.next_u).should eq(UInt32) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "sys/random" | ||
|
||
# Generates random numbers from a secure source of the system. | ||
# | ||
# For example `arc4random` is used on OpenBSD, whereas on Linux it uses | ||
# `getrandom` (if the kernel supports it) and fallbacks on reading from | ||
# `/dev/urandom` on UNIX systems. | ||
class Random::System | ||
include Random | ||
|
||
def initialize | ||
end | ||
|
||
def next_u | ||
Sys::Random.random_number | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters