Rolling Number

admin

Administrator
Staff member
Okay, I've gotten the majority of this down,

but I need to roll a random number that is greater than 30 but not less than 1,

After which I need the number that was rolled to be taken out of 30.

So I would need say:

Cat 1= 15
Total= 15

Cat 2= 3
Total= 12

Etc...


Now to get no less than 1 I would just use.

Math.round(Math.random() + 1);

So could I just do the following?(Saying I have 5 Catagories)


----------------------------
var Total= "30";
var Cat1= Math.round((Math.random() * 30) + 1));

var Total2= Total - Cat1;
var Cat2= Math.round((Math.random() * Total2) + 1));

var Total3= Total2 - Cat2;
var Cat1= Math.round((Math.random() * Total3) + 1));

var Total4= Total3 - Cat3;
var Cat4= Math.round((Math.random() * Total4) + 1));

var Total5= Total4 - Cat4;
var Cat5= Math.round((Math.random() * Total5) + 1));
---------------------------

And then have those corrosponding values shown later in the document.


*** Please don't judge too harshly, this is my first randomization script***


Any Help is appreciated.

Thanks.
 
Back
Top