super_random 3.2.230118 → 3.2.230213

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/super_random.rb +19 -17
  4. metadata +126 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dda98111d66106fe2b2e3027f1b44c61abe791064a5a39c25d82994023670cf
4
- data.tar.gz: b9b3617b187dd8c3197e4069b0fd18600b9cd9975c64914df65f85bdb8a72b4f
3
+ metadata.gz: 22e0311c10d4d5713318a8d42b1710477c60f93ffbcda9014d125761246d4c94
4
+ data.tar.gz: a703a7dc1eebb662736a6f45645dc18091cb4c0c717062a83c6285f51c085099
5
5
  SHA512:
6
- metadata.gz: 17627105179fdf958736dddb2c05f85d3fab8573797c10a9777dd23aacf306ea8692aaf6a202c2bfd05a9cc53df313ad6a50d4141a57b80063e74696a5cc3a85
7
- data.tar.gz: 116b6e7d203bde17193088afbe2badf0dcf74a71a4b6fd1cf72f3462a4d66e598465f0551d078227ede39bace27c98187a83c6dab778cf3ba30bcdabba7be0ee
6
+ metadata.gz: 44b375eae14a0ef677074d24b1b3c60fcf0021f9ab6074f9e0ad4237a8f92acf7aba25735d3fe314376d3675beb0f43e94b18bd62dbb3541a93f9cb887dd8185
7
+ data.tar.gz: 3af65a15f411e9c02d729131a9002d34de5cb4a342a6cc6df72f9732ce2419a4ba4e016c3bc330025d03a077573250cc3ac0eb8e28ef1d8126d7e78a1903b09d
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SuperRandom
2
2
 
3
- * [VERSION 3.2.230118](https://github.com/carlosjhr64/super_random/releases)
3
+ * [VERSION 3.2.230213](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.2.230118"
20
+ SuperRandom::VERSION #~> ^3.\d+.\d+$
21
21
  SuperRandom::DEFAULT_SOURCES #~> www.random.org
22
22
  super_random = SuperRandom.new
23
23
  super_random.sources #~> www.random.org
@@ -83,7 +83,7 @@ super_random.sources
83
83
 
84
84
  (The MIT License)
85
85
 
86
- Copyright (c) 2023 carlosjhr64
86
+ Copyright (c) 2023 CarlosJHR64
87
87
 
88
88
  Permission is hereby granted, free of charge, to any person obtaining
89
89
  a copy of this software and associated documentation files (the
data/lib/super_random.rb CHANGED
@@ -6,27 +6,30 @@ require 'digest'
6
6
  #`ruby`
7
7
 
8
8
  class SuperRandom
9
- VERSION = '3.2.230118'
9
+ VERSION = '3.2.230213'
10
10
  DEFAULT_SOURCES = [
11
- 'https://www.random.org/strings/?num=10&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new',
11
+ 'https://www.random.org/strings/?' \
12
+ 'num=10&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&' \
13
+ 'format=plain&rnd=new'
12
14
  ]
13
15
  MUTEX = Mutex.new
14
16
  DIV = 128.times.inject(''){|h,_|h<<'f'}.to_i(16)
15
17
  RATE_LIMIT = 60 # One minute, be nice!
16
- @@LAST_TIME = Time.now.to_i - RATE_LIMIT - 1
18
+ @@last_time = Time.now.to_i - RATE_LIMIT - 1
17
19
 
18
20
  attr_accessor :first_timeout, :second_timeout, :nevermind
19
21
  attr_reader :sources, :source_count, :byte_count
22
+
20
23
  def initialize(*sources)
21
24
  @sources = sources.empty? ? DEFAULT_SOURCES.dup : sources
22
25
  @byte_count,@source_count = 0,0
23
- @first_timeout,@second_timeout,@nevermind = 3,6,true
26
+ @first_timeout,@second_timeout,@nevermind = 3,3,true
24
27
  end
25
28
 
26
29
  # Returns 64 random bytes(at least from SecureRandom's)
27
30
  def bytes
28
31
  @byte_count,@source_count = 0,0
29
- _do_updates if Time.now.to_i - @@LAST_TIME > RATE_LIMIT
32
+ _do_updates if Time.now.to_i - @@last_time > RATE_LIMIT
30
33
  _get_bytes
31
34
  end
32
35
 
@@ -42,7 +45,7 @@ class SuperRandom
42
45
  hex = hexadecimal
43
46
  x = hex[0...64].to_i(16)
44
47
  y = hex[64..128].to_i(16)
45
- return x,y
48
+ [x,y]
46
49
  end
47
50
 
48
51
  def integer2
@@ -70,7 +73,7 @@ class SuperRandom
70
73
  when Integer
71
74
  return ((integer + SecureRandom.random_number(scale)) % scale)
72
75
  end
73
- raise "rand(scale Integer|Float)"
76
+ raise 'rand(scale Integer|Float)'
74
77
  end
75
78
  alias rand random_number
76
79
 
@@ -84,9 +87,9 @@ class SuperRandom
84
87
  end
85
88
  def roll
86
89
  @big,roll = @big.divmod(@sides)
87
- return roll+@minimum
90
+ roll+@minimum
88
91
  ensure
89
- set_big unless @big>0
92
+ set_big unless @big.positive?
90
93
  end
91
94
  end
92
95
  def dice(sides, minimum:1)
@@ -99,12 +102,13 @@ class SuperRandom
99
102
  def _get_bytes
100
103
  MUTEX.synchronize do
101
104
  SHASUM.update SecureRandom.bytes(64)
102
- SHASUM.digest.chars.map{_1.ord}
105
+ SHASUM.digest.chars.map(&:ord)
103
106
  end
104
107
  ensure
105
108
  MUTEX.synchronize{SHASUM.update SecureRandom.bytes(64)}
106
109
  end
107
110
 
111
+ # source in @sources may be anything URI.open can handle:
108
112
  def _update_with(source)
109
113
  URI.open(source) do |tmp|
110
114
  MUTEX.synchronize do
@@ -116,26 +120,24 @@ class SuperRandom
116
120
  end
117
121
  end
118
122
  rescue
119
- $stderr.puts $!
123
+ warn $!.message
120
124
  end
121
125
 
122
126
  def _do_updates
123
- @@LAST_TIME = Time.now.to_i
127
+ @@last_time = Time.now.to_i
124
128
  threads = @sources.inject([]){|t,s|t.push Thread.new{_update_with s}}
125
129
  begin
126
130
  # Initially, would like to get them all.
127
- Timeout.timeout(@first_timeout){threads.each{_1.join}}
131
+ Timeout.timeout(@first_timeout){threads.each(&:join)}
128
132
  rescue Timeout::Error
129
133
  begin
130
134
  Timeout.timeout(@second_timeout) do
131
135
  # But at this point,
132
136
  # would like to get at least one.
133
- while @services<1 and threads.any?{_1.alive?}
134
- Thread.pass
135
- end
137
+ Thread.pass while @source_count.zero? && threads.any?(&:alive?)
136
138
  end
137
139
  rescue Timeout::Error
138
- Mutex.sychronize{threads.each{_1.exit}} # Exit each thread
140
+ MUTEX.synchronize{threads.each(&:exit)} # Exit each thread
139
141
  raise $! unless @nevermind # Go on if never-minding
140
142
  end
141
143
  end
metadata CHANGED
@@ -1,15 +1,135 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_random
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.230118
4
+ version: 3.2.230213
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-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: cucumber
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '8.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 8.0.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '8.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 8.0.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: help_parser
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '8.2'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 8.2.230210
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '8.2'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 8.2.230210
73
+ - !ruby/object:Gem::Dependency
74
+ name: parser
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '3.2'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.1
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.2'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 3.2.1
93
+ - !ruby/object:Gem::Dependency
94
+ name: rubocop
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.45'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.45.1
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.45'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.45.1
113
+ - !ruby/object:Gem::Dependency
114
+ name: test-unit
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '3.5'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 3.5.7
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '3.5'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 3.5.7
13
133
  description: |
14
134
  You can't get more random than random, but you can try really, really, really hard.
15
135
 
@@ -40,8 +160,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
160
  - !ruby/object:Gem::Version
41
161
  version: '0'
42
162
  requirements:
43
- - 'ruby: ruby 3.2.0 (2022-12-25 revision a528908271) [aarch64-linux]'
44
- rubygems_version: 3.4.3
163
+ - 'git: 2.30'
164
+ - 'ruby: 3.2'
165
+ rubygems_version: 3.4.6
45
166
  signing_key:
46
167
  specification_version: 4
47
168
  summary: You can't get more random than random, but you can try really, really, really