Skip to content

Instantly share code, notes, and snippets.

@DavidMellul
Created February 25, 2018 17:52
Show Gist options
  • Save DavidMellul/93c7b9f2718634f43595d6986a52502e to your computer and use it in GitHub Desktop.
Save DavidMellul/93c7b9f2718634f43595d6986a52502e to your computer and use it in GitHub Desktop.
class PseudoRandomness
# This is the constructor used to instantiate a PseudoRandomness object
def initialize(seed)
@instance_seed = seed
end
def change_seed
@instance_seed = @instance_seed + 1
end
def generate_pseudo_random_value
# That is the evil mathematics part : Multiply the seed 2 times
pseudo_random_value = 2 * @instance_seed
# Here we modify the seed : Increment it
change_seed
return pseudo_random_value
end
end
# We instantiate a new random number generator
random_generator = PseudoRandomness.new(5)
# Now we generate 3 new pseudo random values
3.times { puts random_generator.generate_pseudo_random_value }
# We change the seed and generate 3 new random values
random_generator.change_seed
3.times { puts random_generator.generate_pseudo_random_value }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment