Last active
February 26, 2018 00:30
-
-
Save DavidMellul/b7303c7df97bc8ec760c639d0c31a0bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 by 2 | |
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