I’m trying to generate random data in my rails application.
But I am having a problem with decimal amount. I get an error
saying bad value for range.
while $start < $max
$donation = Donation.new(member: Member.all.sample, amount: [BigDecimal('5.00')...BigDecimal('200.00')].sample,
date_give: Random.date_between(:today...Date.civil(2010,9,11)).to_date,
donation_reason: ['tithes','offering','undisclosed','building-fund'].sample )
$donation.save
$start +=1
end
If you want a random decimal between two numbers, sample isn’t the way to go. Instead, do something like this:
Two other suggestions:
1. if you’ve implemented this, great, but it doesn’t look standard
Random.date_between(:today...Date.civil(2010,9,11)).to_date2.
$variablemeans a global variable in Ruby, so you probably don’t want that.UPDATE — way to really get random date