6 Replies - 2116 Views - Last Post: 12 February 2013 - 03:45 AM Rate Topic: -----

#1 loopConfused  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 10
  • Joined: 18-January 13

Histogram random number

Posted 01 February 2013 - 11:19 AM

How would I make a program generate x amount of integers from the range of 1 through 100 and than store those using arrays and/or hashes.
Is This A Good Question/Topic? 0
  • +

Replies To: Histogram random number

#2 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 907
  • View blog
  • Posts: 3,173
  • Joined: 12-May 09

Re: Histogram random number

Posted 01 February 2013 - 11:54 AM

What have you tried? Do you have any code? The box you typed that in asks you to show us what you've worked on so far because we won't do homework for you.
Was This Post Helpful? 0
  • +
  • -

#3 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1372
  • View blog
  • Posts: 3,472
  • Joined: 28-November 09

Re: Histogram random number

Posted 01 February 2013 - 11:39 PM

Look into ranges, random, and the Enumerable module.
Was This Post Helpful? 1
  • +
  • -

#4 loopConfused  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 10
  • Joined: 18-January 13

Re: Histogram random number

Posted 04 February 2013 - 10:39 AM

This is what I have so far. But Is there a way I can order these in 1-10 all the way up to 91-100 doing an if statement?
Please and thanks for the understanding.
histogram = array.new(10, 0)
for i in 1..200
  num = 1 + rand(100)
  histogram[(num/10).ceil-1]+= 1
  end
puts "Range #    " + "Found    " + "Chart"

Was This Post Helpful? 0
  • +
  • -

#5 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1372
  • View blog
  • Posts: 3,472
  • Joined: 28-November 09

Re: Histogram random number

Posted 04 February 2013 - 07:22 PM

http://ruby-doc.org/...Enumerable.html
Was This Post Helpful? 2
  • +
  • -

#6 tycos  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 53
  • Joined: 12-February 13

Re: Histogram random number

Posted 12 February 2013 - 03:28 AM

Hello, I am not 100 percent what you want here but looking at previous answer maybe something like this?

histogram = []

for i in 1..200
num = 1 + rand(100)
histogram << num
end



Was This Post Helpful? 0
  • +
  • -

#7 tycos  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 53
  • Joined: 12-February 13

Re: Histogram random number

Posted 12 February 2013 - 03:45 AM

Sorry accidentally posted before I had finished typing:

That would create an list of 200 numbers between 1-100, I am not quite sure what you want to do though can you explain more?

group_by

Maybe this page will help?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1