Skip to content

Instantly share code, notes, and snippets.

@ioquatix
Created October 11, 2019 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioquatix/03af159c48192d97a3c72afaf58da473 to your computer and use it in GitHub Desktop.
Save ioquatix/03af159c48192d97a3c72afaf58da473 to your computer and use it in GitHub Desktop.
#!/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
@ioquatix
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment