super_random 3.0.230113 → 3.2.230116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/super_random.rb +55 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80443021c230106600a502974f5ae31b39f6e6f22b5c1e50eef7a00f03b8c9b9
|
4
|
+
data.tar.gz: c4133b454e2e339d5f59d9d64da877fa3ae8831fe701b9846bd86d0cd79906f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eee1ab617d8e57d836f519f96c504ba3e1bb8331ab3e7e300b3cf8360711e4fe688016af2fe37c0ef3f5fb60b74f7883b36c17ccfd496a4a227d416ddf0f8489
|
7
|
+
data.tar.gz: 3cee029f0a3ad6ee2a730934112b91a7997ac55ce0cc760ce17fde375ef5fb87fb0b88cc94dbc90dd73d1dbbb10c63f49467d61fb1f04a878840ad0b42b5afda
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SuperRandom
|
2
2
|
|
3
|
-
* [VERSION 3.
|
3
|
+
* [VERSION 3.2.230116](https://github.com/carlosjhr64/super_random/releases)
|
4
4
|
* [github](https://github.com/carlosjhr64/super_random)
|
5
5
|
* [rubygems](https://rubygems.org/gems/super_random)
|
6
6
|
|
@@ -17,7 +17,7 @@ You can't get more random than random, but you can try really, really, really ha
|
|
17
17
|
## SYNOPSIS:
|
18
18
|
```ruby
|
19
19
|
require 'super_random'
|
20
|
-
SuperRandom::VERSION #=> "3.
|
20
|
+
SuperRandom::VERSION #=> "3.2.230116"
|
21
21
|
SuperRandom::DEFAULT_SOURCES #~> www.random.org
|
22
22
|
super_random = SuperRandom.new
|
23
23
|
super_random.sources #~> www.random.org
|
@@ -34,7 +34,10 @@ super_random.source_count #=> 0
|
|
34
34
|
super_random.byte_count #=> 0
|
35
35
|
# Snapshots from your webcam can be a good entropy source:
|
36
36
|
super_random = SuperRandom.new('/var/lib/motion/lastsnap.jpg')
|
37
|
-
super_random.sources
|
37
|
+
super_random.sources #=> ["/var/lib/motion/lastsnap.jpg"]
|
38
|
+
# Dice!
|
39
|
+
d6 = super_random.dice(6)
|
40
|
+
d6.roll #~> ^[123456]$
|
38
41
|
```
|
39
42
|
## METHODOLOGY:
|
40
43
|
|
data/lib/super_random.rb
CHANGED
@@ -6,7 +6,7 @@ require 'digest'
|
|
6
6
|
#`ruby`
|
7
7
|
|
8
8
|
class SuperRandom
|
9
|
-
VERSION = '3.
|
9
|
+
VERSION = '3.2.230116'
|
10
10
|
DEFAULT_SOURCES = [
|
11
11
|
'https://www.random.org/strings/?num=10&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new',
|
12
12
|
]
|
@@ -34,17 +34,69 @@ class SuperRandom
|
|
34
34
|
bytes.map{_1.to_s(16).rjust(2,'0')}.join
|
35
35
|
end
|
36
36
|
|
37
|
+
def integer
|
38
|
+
hexadecimal.to_i(16)
|
39
|
+
end
|
40
|
+
|
41
|
+
def xy
|
42
|
+
hex = hexadecimal
|
43
|
+
x = hex[0...64].to_i(16)
|
44
|
+
y = hex[64..128].to_i(16)
|
45
|
+
return x,y
|
46
|
+
end
|
47
|
+
|
48
|
+
def integer2
|
49
|
+
# An alternate way to generate an integer
|
50
|
+
x,y = xy
|
51
|
+
# I think this is Binomial(Gaussian in the limit) around zero?
|
52
|
+
x - y
|
53
|
+
end
|
54
|
+
|
55
|
+
def float
|
56
|
+
Rational(integer, DIV).to_f
|
57
|
+
end
|
58
|
+
|
59
|
+
def float2
|
60
|
+
# An alternate way to generate a float...
|
61
|
+
x,y = xy
|
62
|
+
# ...but what distribution is this?
|
63
|
+
Rational(x,y).to_f
|
64
|
+
rescue ZeroDivisionError
|
65
|
+
# Fat chance!
|
66
|
+
return 0 if x == 0
|
67
|
+
1.0/0.0
|
68
|
+
end
|
69
|
+
|
37
70
|
def random_number(scale=1.0)
|
38
71
|
case scale
|
39
72
|
when Float
|
40
|
-
return scale *
|
73
|
+
return scale * float
|
41
74
|
when Integer
|
42
|
-
return ((
|
75
|
+
return ((integer + SecureRandom.random_number(scale)) % scale)
|
43
76
|
end
|
44
77
|
raise "rand(scale Integer|Float)"
|
45
78
|
end
|
46
79
|
alias rand random_number
|
47
80
|
|
81
|
+
class Dice
|
82
|
+
private def set_big
|
83
|
+
@big = @rng.integer + SecureRandom.random_number(@sides)
|
84
|
+
end
|
85
|
+
def initialize(sides, minimum:1, rng:SuperRandom.new)
|
86
|
+
@sides,@minimum,@rng = sides,minimum,rng
|
87
|
+
set_big
|
88
|
+
end
|
89
|
+
def roll
|
90
|
+
@big,roll = @big.divmod(@sides)
|
91
|
+
return roll+@minimum
|
92
|
+
ensure
|
93
|
+
set_big unless @big>0
|
94
|
+
end
|
95
|
+
end
|
96
|
+
def dice(sides, minimum:1)
|
97
|
+
Dice.new(sides, minimum:minimum, rng:self)
|
98
|
+
end
|
99
|
+
|
48
100
|
private
|
49
101
|
|
50
102
|
SHASUM = Digest::SHA2.new(512)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_random
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.230116
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CarlosJHR64
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
You can't get more random than random, but you can try really, really, really hard.
|