Question: I tried to make the combination of `6 with 5` times. Like from 1 to 6 I want to generate randomly similarly `7 to 12` and `13 to 18` upto `25 to 30`.
I tried this like

```
setInterval(function() {
  var number = 1 + Math.floor(Math.random() * 6); //i tried from 1 to 6
    $('#my_div1').text(number);
     var number = 7 + Math.floor(Math.random() * 12); // i tried from 7 to 12
    $('#my_div2').text(number);
     var number = 13 + Math.floor(Math.random() * 18); // from 13 to 18
    $('#my_div3').text(number);
     var number = 19 + Math.floor(Math.random() * 24); //from 19 to 24
    $('#my_div4').text(number);
     var number = 25 + Math.floor(Math.random() * 30);  // from 25 to 30
    $('#my_div5').text(number);
  },
1000);

```

For the first one itself is working for the next i didn't get proper value. I tried this previously in php with `rand(1,5);` like that But i am not sure how to do this in javascript. Any Suggestion would be great.

Here is the **[Fiddle](http://jsfiddle.net/bxZ9G/5/)**

Answer: 
I guess you need this:

```
setInterval(function() {
  var number = 1 + Math.floor(Math.random() * 6); //i tried from 1 to 6
    $('#my_div1').text(number);
     var number = 7 + Math.floor(Math.random() * 6); // i tried from 7 to 12
    $('#my_div2').text(number);
     var number = 13 + Math.floor(Math.random() * 6); // from 13 to 18
    $('#my_div3').text(number);
     var number = 19 + Math.floor(Math.random() * 6); //from 19 to 24
    $('#my_div4').text(number);
     var number = 25 + Math.floor(Math.random() * 6);  // from 25 to 30
    $('#my_div5').text(number);
  },
1000);

```

**updated the fiddle** <http://jsfiddle.net/bxZ9G/8/>
Abstract equation for random number in specified range should be

> 
> Min + (int)(Math.random() \* ((Max - Min) + 1))
> 
> 
> 

So in your case your code might look like

```
function getRandomRange(min, max) {
    return min + Math.floor(Math.random() * ((max - min) + 1));
}
setInterval(function() {
    var number = getRandomRange(1, 6); //i tried from 1 to 6
    $('#my_div1').text(number);
    var number = getRandomRange(7, 12); // i tried from 7 to 12
    $('#my_div2').text(number);
    var number = getRandomRange(13, 18); // from 13 to 18
    $('#my_div3').text(number);
    var number = getRandomRange(19, 24); //from 19 to 24
    $('#my_div4').text(number);
    var number = getRandomRange(25, 30);  // from 25 to 30
    $('#my_div5').text(number);
}, 1000);

```

Here's the fixed fiddle: **<http://jsfiddle.net/bxZ9G/6/>**