-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathname_gen.rb
35 lines (35 loc) · 961 Bytes
/
name_gen.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Funky
def initialize
if !defined?( @@random_device)
if File.exists? "/dev/urandom"
@@random_device = File.open "/dev/urandom", "r"
elsif File.exists? "/dev/random"
@@random_device = File.open "/dev/random", "r"
else
raise RuntimeError, "Can't find random device"
end
end
end
def test_for_unix_randomness
while true
word = @@random_device.read(16).unpack("h8 h4 h4 h4 h12").join "-"
ending = word.split('').values_at(-2,-1).join
puts ending
if ['in','uk','us','me','co','ca','es','pe','tv','cc'].include? ending
puts word
break
end
end
end
def failing_test_for_unix_randomness
while true
word = @@random_device.read(16).unpack("h8 h4 h4 h4 h12").join "-"
ending = word.split('').values_at(-2,-1).join
puts ending
if ['us','me','es'].include? ending
puts word
break
end
end
end
end