Created
October 11, 2019 22:05
-
-
Save ioquatix/03af159c48192d97a3c72afaf58da473 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
spread = {} | |
class ShiftRandom | |
def initialize(seed = 1) | |
@seed = seed | |
@accumulator = seed | |
end | |
def next | |
mask = @accumulator | |
@accumulator <<= 1 | |
@seed = (@seed + (@seed ^ mask)) % (2**32) | |
@accumulator = (@accumulator + (@accumulator ^ @seed)) % (2**32) | |
end | |
end | |
random = ShiftRandom.new | |
numbers = File.open("numbers.txt", "w+") | |
10000.times do | |
numbers.puts random.next | |
end | |
numbers.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Distribution of default seed: https://www.answerminer.com/calculators/histogram?id=a365b3c97f72303a