Histogram random number

Page 1 of 1

6 Replies - 2464 Views - Last Post: 12 February 2013 - 03:45 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=310764&amp;s=df49ee777ec5abaa2c5752d64737c087&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 loopConfused

Reputation: 2
• 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

• I wrote you an code

Reputation: 1010
• Posts: 3,515
• 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.

#3 Lemur

• Pragmatism over Dogma

Reputation: 1438
• Posts: 3,609
• Joined: 28-November 09

Re: Histogram random number

Posted 01 February 2013 - 11:39 PM

Look into ranges, random, and the Enumerable module.

#4 loopConfused

Reputation: 2
• 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"
```

#5 Lemur

• Pragmatism over Dogma

Reputation: 1438
• Posts: 3,609
• Joined: 28-November 09

Re: Histogram random number

Posted 04 February 2013 - 07:22 PM

http://ruby-doc.org/...Enumerable.html

#6 tycos

Reputation: 4
• 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

```

#7 tycos

Reputation: 4
• 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