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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/main.rb +24 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 955b8d104827d5667a6e410bd90362171706fb1a
4
- data.tar.gz: 3aaa58f27381f77beb0288011bc6eb5a1f88ecc8
3
+ metadata.gz: d234a6ac5f87772dfa6bef3957ca2065dc1c29d1
4
+ data.tar.gz: 26d72c7be60d17f62ddd3b0db0227f7ac54d11ac
5
5
  SHA512:
6
- metadata.gz: 6f733478c4838d75d36af2f4131af720fd8b5eb360262de5ed729603e9fc0bd48eb6222c7c677f830fcaef8b55737f9277b3e71839d5b222557ea1a0bc0a455e
7
- data.tar.gz: 5ffb513827c50a94992e4a1c8d1c04c4030aeecb74991c6abab4e971c7a137bbfd74d77728890de4487dc2c10c5326b637be762cd08172af57b041b23536caea
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
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: randomness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SugarRush