Class: CatIpsum::Random
- Inherits:
-
Object
- Object
- CatIpsum::Random
- Defined in:
- lib/cat_ipsum/random.rb
Class Method Summary collapse
- .randomize ⇒ Object
- .randomizer ⇒ Object
- .reset! ⇒ Object
- .sample(array, count: 3) ⇒ Object
- .seed ⇒ Object
- .seed=(value) ⇒ Object
Class Method Details
.randomize ⇒ Object
23 24 25 |
# File 'lib/cat_ipsum/random.rb', line 23 def randomize ::Random.new(seed) end |
.randomizer ⇒ Object
19 20 21 |
# File 'lib/cat_ipsum/random.rb', line 19 def randomizer @randomizer ||= randomize end |
.reset! ⇒ Object
14 15 16 17 |
# File 'lib/cat_ipsum/random.rb', line 14 def reset! @randomizer = randomize true end |
.sample(array, count: 3) ⇒ Object
27 28 29 |
# File 'lib/cat_ipsum/random.rb', line 27 def sample(array, count: 3) array.shuffle(random: randomizer).take(count) end |
.seed ⇒ Object
4 5 6 |
# File 'lib/cat_ipsum/random.rb', line 4 def seed @seed ||= ::Random.new_seed end |
.seed=(value) ⇒ Object
8 9 10 11 12 |
# File 'lib/cat_ipsum/random.rb', line 8 def seed=(value) @seed = value reset! value end |