Skip to content

Instantly share code, notes, and snippets.

@ShaneQful
Created February 18, 2013 12:20
Show Gist options
  • Save ShaneQful/4976974 to your computer and use it in GitHub Desktop.
Save ShaneQful/4976974 to your computer and use it in GitHub Desktop.
Generator Script for Information Systems 2 Assignment Note: This was not part of the assignment and therefore it isn't plagiarism to use this & obviously there is no point submitting this code.
#!/usr/bin/ruby
=begin
Copyright (c) 2013 Shane Quigley
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=end
def gen_trans max_ops, int_bound
num_ops = rand(max_ops) + 1
out = ""
num_ops.times do
if(rand(2) != 0)
out += "#{rand(1000)} #{rand(2*int_bound) - 2*int_bound}\n"
else
out += "#{rand(1000)} READ\n"
end
end
return out
end
def print_usage
print "Usage:\nruby generate_transactions.rb #_transactions max_#_"
print "of_ops_per_transaction bound_on_integer_ops\n"
print "\neg. ruby generate_transactions.rb 3 4 100000\n"
print "Produces something like:\n"
print "\t745 -1526\n"
print "\t896 READ\n"
print "\t562 -1374\n"
print "\t\n"
print "\t386 READ\n"
print "\t249 -473\n"
print "\t905 READ\n"
print "\t488 -1036\n"
print "\t\n"
print "\t70 -621\n"
print "\t373 -1605\n"
print "\t\n"
end
def args_are_numbers
ARGV.each do |a|
if(a.match(/\d+/).to_s.size != a.size)
return false
end
end
true
end
if(!ARGV.empty? && args_are_numbers)
begin
ARGV[0].to_i.times do
puts gen_trans(ARGV[1].to_i, ARGV[2].to_i)
puts
end
rescue
print_usage
end
else
print_usage
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment