Skip to content

Instantly share code, notes, and snippets.

@cwgem
Created July 28, 2011 17:05
Show Gist options
  • Select an option

  • Save cwgem/1111966 to your computer and use it in GitHub Desktop.

Select an option

Save cwgem/1111966 to your computer and use it in GitHub Desktop.
ランダムデータ
# ランダム数 最小-最大
def range_rand(min,max)
min + rand(max-min)
end
# ランダム名前
$names = File.new('names.txt', 'r').readlines.map {|line| line.chomp}
def rand_name
$names[rand($names.length)]
end
# ランダムデータで社員3人作ります
employees = Array.new(3) { |index|
employee = Employee.new
employee.first_name = rand_name
employee.last_name = rand_name
employee.monthly_sales = range_rand(1000,10000)
employee
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment