Be aware that when you do a rand(100) that it is inclusive of zero so
you will need to adjust your arange to include it (arange=[0..30])

def getNum
  a = b = c = d = 0
  1000.times do |foo|
  num= rand(100)
  case num
    when 1..30
      a += 1
    when 31..60
      b += 1
    when 61..100
      c += 1
    else 
      d += 1
  end
  end #loop
  printf(" a: %i\n b: %i\n c: %i\n d: %i", a,b,c,d)
end

getNum

Results:
 a: 283
 b: 296
 c: 406
 d: 15  

--Mark


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Chris McMahon
Sent: Tuesday, February 13, 2007 12:57 PM
To: [email protected]
Subject: Re: [Wtr-general] OT: algorithm help?

> That is, "many" should be >= 1000.

That won't be a problem in this case.

-Chris
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to