guided_randomness 0.1.2 → 0.1.3
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.
- data/lib/guided_randomness.rb +10 -19
- data/lib/guided_randomness/version.rb +1 -1
- metadata +1 -1
data/lib/guided_randomness.rb
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
class Array
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
def get_rand(weights)
|
3
|
+
raise "Wrong number of array elements!" unless weights.size == self.size
|
4
|
+
|
5
|
+
total = weights.inject(0, :+)
|
6
|
+
point = Kernel.rand * total
|
7
|
+
|
8
|
+
self.each_with_index do |element, i|
|
9
|
+
return element if weights[i] >= point
|
10
|
+
point -= weights[i]
|
11
11
|
end
|
12
|
-
array_to_load = []
|
13
|
-
hash.each_pair do |k,v|
|
14
|
-
v.times do
|
15
|
-
array_to_load << k
|
16
|
-
end
|
17
|
-
end
|
18
|
-
value = rand(3) - 1
|
19
|
-
array_to_load.sort { |x,y| rand(3)-1 }.first
|
20
12
|
end
|
21
|
-
|
22
|
-
end
|
13
|
+
end
|