randomness 0.0.0 → 0.0.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.
- checksums.yaml +4 -4
- data/lib/main.rb +24 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d234a6ac5f87772dfa6bef3957ca2065dc1c29d1
|
4
|
+
data.tar.gz: 26d72c7be60d17f62ddd3b0db0227f7ac54d11ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e180c4be2e872476b3ac37efac3d4192c1f69fb79a9b1e1f0dc8e414b4b1ea758a3be8ed74c3e128a4cae5f1e4dc56b959af11405584b0fb715b690a8bdf5478
|
7
|
+
data.tar.gz: 4c72d2b9f5f4d48bb5779152a2a3642bf52d88c0308de9b6e20ab0bd016794b2d606ce3cd7e99fbe32e530a2f113559b1f3224e35ce14440b90b27758a9d8301
|
data/lib/main.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
module Randomness
|
2
|
+
#Sets the random seed to a value based on the current time.
|
3
|
+
def randomizeseed()
|
4
|
+
time = Time.now()
|
5
|
+
srand(time.yday * (time.usec - time.sec))
|
6
|
+
end
|
2
7
|
#Returns a random number between min and max(inclusive of both end points).
|
3
8
|
def randint(min, max)
|
4
9
|
return rand(max - min + 1) + min
|
@@ -7,4 +12,22 @@ module Randomness
|
|
7
12
|
def randchoice(list)
|
8
13
|
return list[rand(list.size())]
|
9
14
|
end
|
10
|
-
|
15
|
+
#Returns the specified number of choices from the list. Returns nil if the amount is greater than the list size.
|
16
|
+
#Every element in the given list will be in the returned list no more than 1 time.
|
17
|
+
def randchoices(list, amount)
|
18
|
+
return nil if amount > list.size()
|
19
|
+
|
20
|
+
return_list = []
|
21
|
+
for i in 1..amount
|
22
|
+
index = rand(list.size())
|
23
|
+
choice = list[index]
|
24
|
+
return_list << choice
|
25
|
+
list.delete_at(index)
|
26
|
+
end
|
27
|
+
return return_list
|
28
|
+
end
|
29
|
+
#Returns a random word from a string.
|
30
|
+
def randword(string)
|
31
|
+
return randchoice(string.split(' '))
|
32
|
+
end
|
33
|
+
end
|