Class: CatIpsum::Random

Inherits:
Object
  • Object
show all
Defined in:
lib/cat_ipsum/random.rb

Class Method Summary collapse

Class Method Details

.randomizeObject



23
24
25
# File 'lib/cat_ipsum/random.rb', line 23

def randomize
  ::Random.new(seed)
end

.randomizerObject



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

.seedObject



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