# Random number generating

how can i create a random number that is in between multiple variables. for example 0-10, 100-110.

it can be in between either of the two options but no greater or less

``````If you have multiple ranges, put them in an array:
var arr=[[0,5],[100,105]];

get a random index of the array:

r=arr[Math.floor(Math.random()*arr.length)],
min=r[0], max=r[1];

then generate the random number from the selected range.

Math.floor(Math.random()*(max-min+1)+min)
``````

This code is working in Konqueror 4.5.5 and Firefox 4.0b9

``````
<script type="text/javascript">

var A =[ [0,10], [100,110]];
var t = String(new Date().getTime()).slice(this.length-2);

var r = A[Math.floor(Math.random()*A.length)];
var min=r[0];
var max=r[1];
var mod = max - min + 1;
var kalan = Number(t) % mod;
var result = min + kalan;

</script>

``````

without using Math.random

``````
<script type="text/javascript">

var A =[ [0,10], [100,110]];
var s = String(new Date().getTime());
var d = s.slice(this.length-1);
var t=  s.slice(this.length-2);